Part Number Hot Search : 
RT922807 1212S N80P53RS 2SC509 15005 RT9259PA 141000 24C32
Product Description
Full Text Search
 

To Download PIC16F917 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2005 microchip technology inc. preliminary ds41250d PIC16F917/916/914/913 data sheet 28/40/44-pin flash-based, 8-bit cmos microcontrollers with lcd driver and nanowatt technology
ds41250d-page ii preliminary ? 2005 microchip technology inc. information contained in this publication regarding device applications and the like is provi ded only for your convenience and may be superseded by updates. it is your responsibility to ensure that your application m eets with your specifications. microchip makes no representations or war- ranties of any kind whether express or implied, written or oral, statutory or otherwise, related to the information, including but not limited to its condition, quality, performance, merchantability or fitness for purpose . microchip disclaims all liability arising from this information and its use. use of microchip?s products as critical components in life support systems is not authorized except with express written approval by microchip. no licenses are conveyed, implicitly or otherwise, under any microchip intellectual property rights. trademarks the microchip name and logo, the microchip logo, accuron, dspic, k ee l oq , micro id , mplab, pic, picmicro, picstart, pro mate, powersmart, rfpic, and smartshunt are registered trademarks of micr ochip technology incorporated in the u.s.a. and other countries. amplab, filterlab, migratable memory, mxdev, mxlab, picmaster, seeval, smartsensor and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. analog-for-the-digital age, app lication maestro, dspicdem, dspicdem.net, dspicworks, ecan, economonitor, fansense, flexrom, fuzzylab, in-circuit serial programming, icsp, icepic, linear active thermistor, mpasm, mplib, mplink, mpsim, pickit, picdem, picdem.net, piclab, pictail, powercal, powerinfo, powermate, powertool, rflab, rfpicdem, select mode, smart serial, smarttel, total endurance and wiperlock are trademarks of microchip tec hnology incorporated in the u.s.a. and other countries. sqtp is a service mark of mi crochip technology incorporated in the u.s.a. all other trademarks mentioned herein are property of their respective companies. ? 2005, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. note the following details of the code protection feature on microchip devices: ? microchip products meet the specification cont ained in their particular microchip data sheet. ? microchip believes that its family of products is one of the mo st secure families of its kind on the market today, when used i n the intended manner and under normal conditions. ? there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specif ications contained in microchip?s data sheets. most likely, the person doing so is engaged in theft of intellectual property. ? microchip is willing to work with the customer who is concerned about the integrity of their code. ? neither microchip nor any other semiconductor manufacturer c an guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are co mmitted to continuously improvi ng the code protection features of our products. attempts to break microchip?s c ode protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2002 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona and mountain view, california in october 2003. the company?s quality system processes and procedures are for its picmicro ? 8-bit mcus, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified.
? 2005 microchip technology inc. preliminary ds41250d-page 1 PIC16F917/916/914/913 28/40/44-pin flash-based, 8-bit cmos microcontrollers with lcd driver and nanowatt technology high-performance risc cpu: ? only 35 instructions to learn: - all single-cycle instructions except branches ? operating speed: - dc ? 20 mhz oscillator/clock input - dc ? 200 ns instruction cycle ? program memory read (pmr) capability ? interrupt capability ? 8-level deep hardware stack ? direct, indirect and relative addressing modes special microcontroller features: ? precision internal oscillator: - factory calibrated to 1% - software selectable frequency range of 8 mhz to 32 khz - software tunable - two-speed start-up mode - crystal fail detect for critical applications - clock mode switching during operation for power savings ? power-saving sleep mode ? wide operating voltage range (2.0v-5.5v) ? industrial and extended temperature range ? power-on reset (por) ? power-up timer (pwrt) and oscillator start-up timer (ost) ? brown-out reset (bor) with software control option ? enhanced low-current watchdog timer (wdt) with on-chip oscillator (software selectable nominal 268 seconds with full prescaler) with software enable ? multiplexed master clear with pull-up/input pin ? programmable code protection ? high-endurance flash/eeprom cell: - 100,000 write flash endurance - 1,000,000 write eeprom endurance - flash/data eeprom retention: > 40 years low-power features: ? standby current: - <100 na @ 2.0v, typical ? operating current: -8.5 a @ 32 khz, 2.0v, typical -100 a @ 1 mhz, 2.0v, typical ? watchdog timer current: -1 a @ 2.0v, typical peripheral features: ? liquid crystal display module: - up to 60 pixel drive capability on 28-pin devices - up to 96 pixel drive capability on 40-pin devices - four commons ? up to 35 i/o pins and 1 input-only pin: - high-current source/sink for direct led drive - interrupt-on-pin change - individually programmable weak pull-ups ? in-circuit serial programming? (icsp?) via two pins ? analog comparator module with: - two analog comparators - programmable on-chip voltage reference (cv ref ) module (% of v dd ) - comparator inputs and outputs externally accessible ? a/d converter: - 10-bit resolution and up to 8 channels ? timer0: 8-bit timer/counter with 8-bit programmable prescaler ? enhanced timer1: - 16-bit timer/counter with prescaler - external gate input mode - option to use osc1 and osc2 as timer1 oscillator if intoscio or lp mode is selected ? timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler ? addressable universal synchronous asynchronous receiver transmitter (ausart) ? up to 2 capture, compare, pwm modules: - 16-bit capture, max. resolution 12.5 ns - 16-bit compare, max. resolution 200 ns - 10-bit pwm, max. frequency 20 khz ? synchronous serial port (ssp) with i 2 c ?
PIC16F917/916/914/913 ds41250d-page 2 preliminary ? 2005 microchip technology inc. pin diagrams ? pic16f914/917, 40-pin device program memory data memory i/o 10-bit a/d (ch) lcd (segment drivers) ccp timers 8/16- bit flash (words/bytes) sram (bytes) eeprom (bytes) pic16f913 4k/7k 256 256 24 5 16 1 2/1 pic16f914 4k/7k 256 256 35 8 24 2 2/1 pic16f916 8k/14k 352 256 24 5 16 1 2/1 PIC16F917 8k/14k 352 256 35 8 24 2 2/1 40-pin pdip 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 pic16f914/917 re3/mclr /v pp ra0/an0/c1-/seg12 ra1/an1/c2-/seg7 ra2/an2/c2+/v ref -/com2 ra3/an3/c1+/v ref +/seg15 ra4/c1out/t0cki/seg4 ra5/an4/c2out/ss /seg5 re0/an5/seg21 re1/an6/seg22 re2/an7/seg23 v dd v ss ra7/osc1/clki/t1osi ra6/osc2/clko/t1oso rc0/vlcd1 rc1/vlcd2 rc2/vlcd3 rc3/seg6 rd0/com3 rd1 rb7/icspdat/icddat/seg13 rb6/icspclk/icdck/seg14 rb5/com1 rb4/com0 rb3/seg3 rb2/seg2 rb1/seg1 rb0/int/seg0 v dd v ss rd7/seg20 rd6/seg19 rd5/seg18 rd4/seg17 rc7/rx/dt/sdi/sda/seg8 rc6/tx/ck/sck/scl/seg9 rc5/t1cki/ccp1/seg10 rc4/t1g /sdo/seg11 rd3/seg16 rd2/ccp2
? 2005 microchip technology inc. preliminary ds41250d-page 3 PIC16F917/916/914/913 pin diagrams ? pic16f913/916, 28-pin 28-pin pdip, soic, ssop 28-pin qfn 10 11 2 3 4 5 6 1 8 7 9 12 13 14 15 16 17 18 19 20 23 24 25 26 27 28 22 21 pic16f913/916 re3/mclr /v pp ra0/an0/c1-/seg12 ra1/an1/c2-/seg7 ra2/an2/c2+/v ref -/com2 ra3/an3/c1+/v ref +/com3/seg15 ra4/c1out/t0cki/seg4 ra5/an4/c2out/ss /seg5 v ss ra7/osc1/clki/t1osi ra6/osc2/clko/t1oso rc0/vlcd1 rc1/vlcd2 rc2/vlcd3 rc3/seg6 rb7/icspdat/icddat/seg13 rb6/icspclk/icdck/seg14 rb5/com1 rb4/com0 rb3/seg3 rb2/seg2 rb1/seg1 rb0/int/seg0 v dd v ss rc7/rx/dt/sdi/sda/seg8 rc6/tx/ck/sck/scl/seg9 rc5/t1cki/ccp1/seg10 rc4/t1g /sdo/seg11 16 2 7 1 3 6 5 4 15 21 19 20 17 18 22 28 26 27 23 24 25 14 8 10 9 13 12 11 pic16f913/916 ra1/an1/c2-/seg7 ra0/an0/c1-/seg12 re3/mclr /v pp rb7/icspdat/icddat/seg13 rb6/icspclk/icdck/seg14 rb5/com1 rb4/com0 rc0/vlcd1 rc1/vlcd2 rc2/vlcd3 rc3/seg6 rc4/t1g /sdo/seg11 rc5/t1cki/ccp1/seg10 rc6/tx/ck/sck/scl/seg9 ra2/an2/c2+/v ref -/com2 ra3/an3/c1+/v ref +/com3/seg15 ra4/c1out/t0cki/seg4 ra5/an4/c2out/ss /seg5 v ss ra7/osc1/clki/t1osi ra6/osc2/clko/t1oso rb3/seg3 rb2/seg2 rb1/seg1 rb0/int/seg0 v dd v ss rc7/rx/dt/sdi/sda/seg8
PIC16F917/916/914/913 ds41250d-page 4 preliminary ? 2005 microchip technology inc. pin diagrams ? pic16f914/917, 44-pin 44-pin tqfp 10 11 2 3 6 1 18 19 20 21 22 12 13 14 15 38 8 7 44 43 42 41 40 39 16 17 29 30 31 32 33 23 24 25 26 27 28 36 34 35 9 37 5 4 pic16f914/917 nc rc0/vlcd1 ra6/osc2/clko/t1oso ra7/osc1/clki/t1osi v ss v dd re2/an7/seg23 re1/an6/seg22 re0/an5/seg21 ra5/an4/c2out/ss /seg5 ra4/c1out/t0cki/seg4 rc7/rx/dt/sdi/sda/seg8 rd4/seg17 rd5/seg18 rd6/seg19 rd7/seg20 v ss v dd rb0/seg0/int rb1/seg1 rb2/seg2 rb3/seg3 nc nc rb4/com0 rb5/com1 rb6/icspclk/icdck/seg14 rb7/icspdat/icddat/seg13 re3/mclr /v pp ra0/c1-/an0/seg12 ra1/c2-/an1/seg7 ra2/an2/c2+/v ref -/com2 ra3/an3/v ref +/c1+/seg15 rc6/tx/ck/sck/scl/seg9 rc5/t1cki/ccp1/seg10 rc4/t1g /sdo/seg11 rd3/seg16 rd2/ccp2 rd1 rd0/com3 rc3/seg6 rc2/vlcd3 rc1/vlcd2 nc 44-pin qfn 10 11 2 3 6 1 18 19 20 21 22 12 13 14 15 38 8 7 44 43 42 41 40 39 16 17 29 30 31 32 33 23 24 25 26 27 28 36 34 35 9 37 5 4 pic16f914/917 ra6/osc2/clk0/t1oso ra7/osc1/clki/t1osi v ss v ss nc v dd re2/an7/seg23 re1/an6/seg22 re0/an5/seg21 ra5/an4/c2out/ss /seg5 ra4/c1out/t0cki/seg4 rc7/rx/dt/sdi/sda/seg8 rd4/seg17 rd5/seg18 rd6/seg19 rd7/seg20 v ss v dd v dd rb0/int/seg0 rb1/seg1 rb2/seg2 rb3/seg3 nc rb4/com0 rb5/com1 rb6/icspclk/icdck/seg14 rb7/icspdat/icddat/seg13 re3/mclr /v pp ra0/an0/c1-/seg12 ra1/an1/c2-/seg7 ra2/an2/c2+/v ref -/com2 ra3/an3/c1+/v ref +/seg15 rc6/tx/ck/sck/scl/seg9 rc5/t1cki/ccp1/seg10 rc4/t1g /sdo/seg11 rd3/seg16 rd2/ccp2 rd1 rd0/com3 rc3/seg6 rc2/vlcd3 rc1/vlcd2 rc0/vldc1
? 2005 microchip technology inc. preliminary ds41250d-page 5 PIC16F917/916/914/913 table of contents 1.0 device overview ............................................................................................................. ............................................................. 7 2.0 memory organization ......................................................................................................... ........................................................ 13 3.0 i/o ports ................................................................................................................... .................................................................. 31 4.0 clock sources ............................................................................................................... ............................................................. 69 5.0 timer0 module ............................................................................................................... ............................................................ 81 6.0 timer1 module with gate control............................................................................................. ................................................. 85 7.0 timer2 module ............................................................................................................... ............................................................ 90 8.0 comparator module........................................................................................................... ......................................................... 93 9.0 liquid crystal display (lcd) driver module.................................................................................. ........................................... 101 10.0 programmable low-voltage detect (plvd) module.............................................................................. .................................. 125 11.0 addressable universal synchronous asynchr onous receiver transmitter (usart)................................................ .............. 127 12.0 analog-to-digital converter (a/d) module................................................................................... ............................................. 143 13.0 data eeprom and flash program memory control ............................................................................... ................................ 153 14.0 ssp module overview ........................................................................................................ ..................................................... 159 15.0 capture/compare/pwm modules ................................................................................................ ............................................ 177 16.0 special features of the cpu................................................................................................ .................................................... 185 17.0 instruction set summary .................................................................................................... ...................................................... 205 18.0 development support........................................................................................................ ....................................................... 215 19.0 electrical specifications.................................................................................................. .......................................................... 221 20.0 dc and ac characteristics graphs and tables................................................................................ ....................................... 247 21.0 packaging information...................................................................................................... ........................................................ 249 appendix a: data sheet revision history........................................................................................ .................................................. 259 appendix b: migrating from other picmicro? devices ............................................................................. ....................................... 259 appendix c: conversion considerations .......................................................................................... ................................................. 260 index .......................................................................................................................... ........................................................................ 261 on-line support................................................................................................................ .................................................................. 269 systems information and upgrade hot line ....................................................................................... ............................................... 269 reader response ................................................................................................................ .............................................................. 270 product identification system .................................................................................................. .......................................................... 271 to our valued customers it is our intention to provide our valued customers with the best documentation possible to ensure successful use of your micro chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be refined and enhanced as new volumes and updates are introduced. if you have any questions or comments regar ding this publication, please contact the marketing communications department via e-mail at docerrors@microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences fr om the data sheet and recommended workarounds, may exist for curren t devices. as device/doc umentation issues become known to us, we will publis h an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particul ar device, please check with one of the following: ? microchip?s worldwide web site; http://www.microchip.com ? your local microchip sales office (see last page) when contacting a sales office, please spec ify which device, revision of silicon and data sheet (include literature number) you are using. customer notification system register on our web site at www.microchip.com to receive the most current information on all of our products.
PIC16F917/916/914/913 ds41250d-page 6 preliminary ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. preliminary ds41250d-page 7 PIC16F917/916/914/913 1.0 device overview this document contains device specific information for the pic16f91x. additional information may be found in the ? picmicro ? mid-range mcu family reference manual ? (ds33023), downloaded from the microchip web site. the reference manual should be considered a complementary document to this data sheet and is highly recommended reading for a better understanding of the device architecture and operation of the peripheral modules. the pic16f91x devices are covered by this data sheet. it is available in 28/40/44-pin packages. figure 1-1 shows a block diagram of the pic16f913/ 916 device and table 1-1 shows the pinout description. figure 1-2 shows a block diagram of the pic16f914/ 917 device and table 1-1 shows the pinout description.
PIC16F917/916/914/913 ds41250d-page 8 preliminary ? 2005 microchip technology inc. figure 1-1: pic16f91 3/916 block diagram power-up timer oscillator start-up timer power-on reset watchdog timer brown-out reset rb0/int/seg0 rb1/seg1 rb2/seg2 rb3/seg3 rb4/com0 rb5/com1 rb6/icspclk/icdck/seg14 rb7/icspdat/icddat/seg13 flash program memory 13 data bus 8 14 program bus instruction reg program counter ram file registers direct addr 7 ram addr 9 addr mux indirect addr fsr reg status reg mux alu w reg instruction decode and control timing generation osc1/clki osc2/clko porta 8 8 8 3 8-level stack (13-bit) 256/352 bytes 4k/8k x 14 v ss ra0/an0/c1-/seg12 ra1/an1/c2-/seg7 ra2/an2/c2+/v ref -/com2 ra3/an3/c1+/v ref +/com3/seg1 5 ra4/c1out/t0cki/seg4 ra5/an4 / c2out/ss /seg5 ra6/osc2/clko/t1oso ra7/osc1/clki/t1osi int configuration internal oscillator v dd block program memory read portc rc0/vlcd1 rc1/vlcd2 rc2/vlcd3 rc3/seg6 rc4/t1g /sdo/seg11 rc5/t1cki/ccp1/seg10 rc6/tx/ck/sck/scl/seg9 rc7/rx/dt/sdi/sda/seg8 porte re3/mclr /v pp (prm) portb plvd lcd data eeprom 256 bytes comparators addressable usart ccp1 ssp timer0 timer1 timer2 10-bit a/d bor
? 2005 microchip technology inc. preliminary ds41250d-page 9 PIC16F917/916/914/913 figure 1-2: pic16f91 4/917 block diagram portd rd0/com3 rd1 rd2/ccp2 rd3/seg16 rd4/seg17 rd5/seg18 rd6/seg19 rd7/seg20 power-up timer oscillator start-up timer power-on reset watchdog timer brown-out reset portb rb0/int/seg0 rb1/seg1 rb2/seg2 rb3/seg3 rb4/com0 rb5/com1 rb6/icspclk/icdck/seg14 rb7/icspdat/icddat/seg1 3 flash program memory 13 data bus 8 14 program bus instruction reg program counter ram file registers direct addr 7 ram addr 9 addr mux indirect addr fsr reg status reg mux alu w reg instruction decode and control timing generation osc1/clki osc2/clko porta 8 8 8 3 8-level stack (13-bit) 256/352 bytes 4k/8k x 14 v ss ra0/an0/c1 -/ seg12 ra1/an1/c2-/seg7 ra2/an2/c2+/v ref -/com2 ra3/an3/c1+/v ref +/seg15 ra4/c1out/t0cki/seg4 ra5/an4 / c2out/ss /seg5 ra6/osc2/clko/t1oso ra7/osc1/clki/t1osi int configuration internal oscillator v dd block program memory read data eeprom 256 bytes portc rc0/vlcd1 rc1/vlcd2 rc2/vlcd3 rc3/seg6 rc4/t1g /sdo/seg11 rc5/t1cki/ccp1/seg10 rc6/tx/ck/sck/scl/seg9 rc7/rx/dt/sdi/sda/seg8 porte (prm) re0/an5/seg21 re1/an6/seg22 re2/an7/seg23 re3/mclr /v pp plvd lcd comparators addressable usart ccp2 ssp timer0 timer1 timer2 10-bit a/d bor ccp1
PIC16F917/916/914/913 ds41250d-page 10 preliminary ? 2005 microchip technology inc. table 1-1: pic16f91x pinout descriptions name function input type output type description ra0/an0/c1-/seg12 ra0 ttl cmos general purpose i/o. an0 an ? analog input channel 0/comparator 1 input ? negative. c1- ? an comparator 1 negative input. seg12 ? an lcd analog output. ra1/an1/c2-/seg7 ra1 ttl cmos general purpose i/o. an1 an ? analog input channel 1/comparator 2 input ? negative. c2- ? an comparator 2 negative input. seg7 ? an lcd analog output. ra2/an2/c2+/v ref -/com2 ra2 ttl cmos general purpose i/o. an2 an ? analog input channel 2/comparator 2 input ? positive. c2+ ? an comparator 2 positive input. v ref - an ? external voltage reference ? negative. com2 ? an lcd analog output. ra3/an3/c1+/v ref +/com3 (1) / seg15 ra3 ttl cmos general purpose i/o. an3 an ? analog input channel 3/comparator 1 input ? positive. c1+ ? an comparator 1 positive input. v ref + an ? external voltage reference ? positive. com3 (1) ? an lcd analog output. seg15 ? an lcd analog output. ra4/c1out/t0cki/seg4 ra4 ttl cmos general purpose i/o. c1out ? cmos comparator 1 output. t0cki st ? timer0 clock input. seg4 ? an lcd analog output. ra5/an4/c2out/ss /seg5 ra5 ttl cmos general purpose i/o. an4 an ? analog input channel 4. c2out ? cmos comparator 2 output. ss ttl ? slave select input. seg5 ? an lcd analog output. ra6/osc2/clko/t1oso ra6 ttl cmos general purpose i/o. osc2 ? xtal crystal/resonator. clko ? cmos t osc /4 reference clock. t1oso ? xtal timer1 oscillator output. ra7/osc1/clki/t1osi ra7 ttl cmos general purpose i/o. osc1 xtal ? crystal/resonator. clki st ? clock input. t1osi xtal ? timer1 oscillator input. rb0/int/seg0 rb0 ttl cmos general purpose i/o. individually enabled pull-up. int st ? external interrupt pin. seg0 ? an lcd analog output. rb1/seg1 rb1 ttl cmos general purpose i/o. individually enabled pull-up. seg1 ? an lcd analog output. legend: an = analog input or output cmos = cmos compatible input or output d = direct ttl = ttl compatible input st = schmitt trigger input with cmos levels hv = high voltage xtal = crystal note 1: com3 is available on ra3 for the pic16f913/916 and on rd0 for the pic16f914/917. 2: pins available on pic16f914/917 only.
? 2005 microchip technology inc. preliminary ds41250d-page 11 PIC16F917/916/914/913 rb2/seg2 rb2 ttl cmos general purpose i/o. individually enabled pull-up. seg2 ? an lcd analog output. rb3/seg3 rb3 ttl cmos general purpose i/o. individually enabled pull-up. seg3 ? an lcd analog output. rb4/com0 rb4 ttl cmos general purpose i/o. individually controlled interrupt-on- change. individually enabled pull-up. com0 ? an lcd analog output. rb5/com1 rb5 ttl cmos general purpose i/o. individually controlled interrupt-on- change. individually enabled pull-up. com1 ? an lcd analog output. rb6/icspclk/icdck/seg14 rb6 ttl cmos general purpose i/o. individually controlled interrupt-on- change. individually enabled pull-up. icspclk st ? icsp? clock. icdck st ? icd clock i/o. seg14 ? an lcd analog output. rb7/icspdat/icddat/seg13 rb7 ttl cmos general purpose i/o. individually controlled interrupt-on- change. individually enabled pull-up. icspdat st cmos icsp data i/o. icddat st cmos icd data i/o. seg13 ? an lcd analog output. rc0/vlcd1 rc0 st cmos general purpose i/o. vlcd1 an ? lcd analog input. rc1/vlcd2 rc1 st cmos general purpose i/o. vlcd2 an ? lcd analog input. rc2/vlcd3 rc2 st cmos general purpose i/o. vlcd3 an ? lcd analog input. rc3/seg6 rc3 st cmos general purpose i/o. seg6 ? an lcd analog output. rc4/t1g /sdo/seg11 rc4 st cmos general purpose i/o. t1g st ? timer1 gate input. sdo ? cmos serial data output. seg11 ? an lcd analog output. rc5/t1cki/ccp1/seg10 rc5 st cmos general purpose i/o. t1cki st ? timer1 clock input. ccp1 st cmos capture 1 input/compare 1 output/pwm 1 output. seg10 ? an lcd analog output. rc6/tx/ck/sck/scl/seg9 rc6 st cmos general purpose i/o. tx ? cmos usart asynchronous serial transmit. ck st cmos usart synchronous serial clock. sck st cmos spi? clock. scl st cmos i 2 c? clock. seg9 ? an lcd analog output. table 1-1: pic16f91x pinout descriptions (continued) name function input type output type description legend: an = analog input or output cmos = cmos compatible input or output d = direct ttl = ttl compatible input st = schmitt trigger input with cmos levels hv = high voltage xtal = crystal note 1: com3 is available on ra3 for the pic16f913/916 and on rd0 for the pic16f914/917. 2: pins available on pic16f914/917 only.
PIC16F917/916/914/913 ds41250d-page 12 preliminary ? 2005 microchip technology inc. rc7/rx/dt/sdi/sda/seg8 rc7 st cmos general purpose i/o. rx st ? usart asynchronous serial receive. dt st cmos usart synchronous serial data. sdi st cmos spi? data input. sda st cmos i 2 c? data. seg8 ? an lcd analog output. rd0/com3 (1, 2) rd0 st cmos general purpose i/o. com3 ? an lcd analog output. rd1 (2) rd1 st cmos general purpose i/o. rd2/ccp2 (2) rd2 st cmos general purpose i/o. ccp2 st cmos capture 2 input/compare 2 output/pwm 2 output. rd3/seg16 (2) rd3 st cmos general purpose i/o. seg16 ? an lcd analog output. rd4/seg17 (2) rd4 st cmos general purpose i/o. seg17 ? an lcd analog output. rd5/seg18 (2) rd5 st cmos general purpose i/o. seg18 ? an lcd analog output. rd6/seg19 (2) rd6 st cmos general purpose i/o. seg19 ? an lcd analog output. rd7/seg20 (2) rd7 st cmos general purpose i/o. seg20 ? an lcd analog output. re0/an5/seg21 (2) re0 st cmos general purpose i/o. an5 an ? analog input channel 5. seg21 ? an lcd analog output. re1/an6/seg22 (2) re1 st cmos general purpose i/o. an6 an ? analog input channel 6. seg22 ? an lcd analog output. re2/an7/seg23 (2) re2 st cmos general purpose i/o. an7 an ? analog input channel 7. seg23 ? an lcd analog output. re3/mclr /v pp re3 st ? digital input only. mclr st ? master clear with internal pull-up. v pp hv ? programming voltage. v dd v dd d ? power supply for microcontroller. v ss v ss d ? ground reference for microcontroller. table 1-1: pic16f91x pinout descriptions (continued) name function input type output type description legend: an = analog input or output cmos = cmos compatible input or output d = direct ttl = ttl compatible input st = schmitt trigger input with cmos levels hv = high voltage xtal = crystal note 1: com3 is available on ra3 for the pic16f913/916 and on rd0 for the pic16f914/917. 2: pins available on pic16f914/917 only.
? 2005 microchip technology inc. preliminary ds41250d-page 13 PIC16F917/916/914/913 2.0 memory organization 2.1 program memory organization the PIC16F917/916/914/913 has a 13-bit program counter capable of addressing a 4k x 14 program memory space for the pic16f913/914 (0000h-0fffh) and an 8k x 14 program memory space for the pic16f916/917 (0000h-1fffh). accessing a location above the memory boundaries for the pic16f913 and pic16f914 will cause a wrap around within the first 4k x 14 space. the reset vector is at 0000h and the interrupt vector is at 0004h. figure 2-1: program memory map and stack for the pic16f913/914 figure 2-2: program memory map and stack for the pic16f916/917 pc<12:0> 13 0000h 0004h stack level 1 stack level 8 reset vector interrupt vector call, return retfie, retlw stack level 2 0005h on-chip 1fffh program memory page 0 page 1 07ffh 0800h 0fffh 1000h pc<12:0> 13 0000h 0004h stack level 1 stack level 8 reset vector interrupt vector call, return retfie, retlw stack level 2 0005h on-chip 1fffh program memory page 0 page 1 page 2 page 3 07ffh 0800h 0fffh 1000h 17ffh 1800h
PIC16F917/916/914/913 ds41250d-page 14 preliminary ? 2005 microchip technology inc. 2.2 data memory organization the data memory is partitioned into multiple banks which contain the general purpose registers (gprs) and the special function registers (sfrs). bits rp0 and rp1 are bank select bits. = 00 : bank 0 = 01 : bank 1 = 10 : bank 2 = 11 : bank 3 each bank extends up to 7fh (128 bytes). the lower locations of each bank are reserved for the special function registers. above the special function registers are the general purpose registers, implemented as static ram. all implemented banks contain special function registers. some frequently used special function registers from one bank are mirrored in another bank for code reduction and quicker access. 2.2.1 general purpose register file the register file is organized as 256 x 8 in the pic16f913/914 and 352 x 8 in the pic16f916/917. each register is accessed either directly or indirectly through the file select register (fsr) (see section 2.5 ?indirect addressing, indf and fsr registers? ). 2.2.2 special function registers the special function registers are registers used by the cpu and peripheral functions for controlling the desired operation of the device (see tables 2-1, 2-2, 2-3 and 2-4). these registers are static ram. the special registers can be classified into two sets: core and peripheral. the special function registers associated with the ?core? are described in this section. those related to the operation of the peripheral features are described in the section of that peripheral feature. rp0 rp1 (status<6:5>)
? 2005 microchip technology inc. preliminary ds41250d-page 15 PIC16F917/916/914/913 figure 2-3: pic16f913/916 special function registers file file file file address address address address indirect addr. (1) 00h indirect addr. (1) 80h indirect addr. (1) 100h indirect addr. (1) 180h tmr0 01h option_reg 81h tmr0 101h option_reg 181h pcl 02h pcl 82h pcl 102h pcl 182h status 03h status 83h status 103h status 183h fsr 04h fsr 84h fsr 104h fsr 184h porta 05h trisa 85h wdtcon 105h 185h portb 06h trisb 86h portb 106h trisb 186h portc 07h trisc 87h lcdcon 107h 187h 08h 88h lcdps 108h 188h porte 09h trise 89h lvdcon 109h 189h pclath 0ah pclath 8ah pclath 10ah pclath 18ah intcon 0bh intcon 8bh intcon 10bh intcon 18bh pir1 0ch pie1 8ch eedatl 10ch eecon1 18ch pir2 0dh pie2 8dh eeadrl 10dh eecon2 (1) 18dh tmr1l 0eh pcon 8eh eedath 10eh 18eh tmr1h 0fh osccon 8fh eeadrh 10fh 18fh t1con 10h osctune 90h lcddata0 110h general purpose register (2) 96 bytes 190h tmr2 11h ansel 91h lcddata1 111h t2con 12h pr2 92h 112h sspbuf 13h sspadd 93h lcddata3 113h sspcon 14h sspstat 94h lcddata4 114h ccpr1l 15h wpub 95h 115h ccpr1h 16h iocb 96h lcddata6 116h ccp1con 17h cmcon1 97h lcddata7 117h rcsta 18h txsta 98h 118h txreg 19h spbrg 99h lcddata9 119h rcreg 1ah 9ah lcddata10 11ah 1bh 9bh 11bh 1ch cmcon0 9ch lcdse0 11ch 1dh vrcon 9dh lcdse1 11dh adresh 1eh adresl 9eh 11eh adcon0 1fh adcon1 9fh 11fh general purpose register 96 bytes 20h general purpose register 80 bytes a0h general purpose register 80 bytes 120h efh 16fh 1efh accesses 70h-7fh f0h accesses 70h-7fh 170h accesses 70h-7fh 1f0h 7fh ffh 17fh 1ffh bank 0 bank 1 bank 2 bank 3 unimplemented data memory locations, read as ? 0 ?. note 1: not a physical register. 2: on the pic16f913, unimplemented data memory locations, read as ? 0 ?.
PIC16F917/916/914/913 ds41250d-page 16 preliminary ? 2005 microchip technology inc. figure 2-4: pic16f914/917 special function registers file file file file address address address address indirect addr. (1) 00h indirect addr. (1) 80h indirect addr. (1) 100h indirect addr. (1) 180h tmr0 01h option_reg 81h tmr0 101h option_reg 181h pcl 02h pcl 82h pcl 102h pcl 182h status 03h status 83h status 103h status 183h fsr 04h fsr 84h fsr 104h fsr 184h porta 05h trisa 85h wdtcon 105h 185h portb 06h trisb 86h portb 106h trisb 186h portc 07h trisc 87h lcdcon 107h 187h portd 08h trisd 88h lcdps 108h 188h porte 09h trise 89h lvdcon 109h 189h pclath 0ah pclath 8ah pclath 10ah pclath 18ah intcon 0bh intcon 8bh intcon 10bh intcon 18bh pir1 0ch pie1 8ch eedatl 10ch eecon1 18ch pir2 0dh pie2 8dh eeadrl 10dh eecon2 (1) 18dh tmr1l 0eh pcon 8eh eedath 10eh 18eh tmr1h 0fh osccon 8fh eeadrh 10fh 18fh t1con 10h osctune 90h lcddata0 110h general purpose register (2) 96 bytes 190h tmr2 11h ansel 91h lcddata1 111h t2con 12h pr2 92h lcddata2 112h sspbuf 13h sspadd 93h lcddata3 113h sspcon 14h sspstat 94h lcddata4 114h ccpr2l 15h wpub 95h lcddata5 115h ccpr2h 16h iocb 96h lcddata6 116h ccp2con 17h cmcon1 97h lcddata7 117h rcsta 18h txsta 98h lcddata8 118h txreg 19h spbrg 99h lcddata9 119h rcreg 1ah 9ah lcddata10 11ah ccpr2l 1bh 9bh lcddata11 11bh ccpr2h 1ch cmcon0 9ch lcdse0 11ch ccpr2con 1dh vrcon 9dh lcdse1 11dh adresh 1eh adresl 9eh lcdse2 11eh adcon0 1fh adcon1 9fh 11fh general purpose register 96 bytes 20h general purpose register 80 bytes a0h general purpose register 80 bytes 120h efh 16fh 1efh accesses 70h-7fh f0h accesses 70h-7fh 170h accesses 70h-7fh 1f0h 7fh ffh 17fh 1ffh bank 0 bank 1 bank 2 bank 3 unimplemented data memory locations, read as ? 0 ?. note 1: not a physical register. 2: on the pic16f914, unimplemented data memory locations, read as ? 0 ?.
? 2005 microchip technology inc. preliminary ds41250d-page 17 PIC16F917/916/914/913 table 2-1: PIC16F917/916/914/913 special registers summary bank 0 addr name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por/bor reset value on all other resets (1) bank 0 00h indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx xxxx xxxx 01h tmr0 timer0 module register xxxx xxxx uuuu uuuu 02h pcl program counter?s (pc) least significant byte 0000 0000 0000 0000 03h status irp rp1 rp0 to pd zdcc 0001 1xxx 000q quuu 04h fsr indirect data memory address pointer xxxx xxxx uuuu uuuu 05h porta ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 xxxx xxxx uuuu uuuu 06h portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx uuuu uuuu 07h portc rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 xxxx xxxx uuuu uuuu 08h portd (2) rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 xxxx xxxx uuuu uuuu 09h porte ? ? ? ?re3re2 (2) re1 (2) re0 (2) ---- xxxx ---- uuuu 0ah pclath ? ? ? write buffer for upper 5 bits of program counter ---0 0000 ---0 0000 0bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 0dh pir2 osfif c2if c1if lcdif ?lvdif ? ccp2if 0000 -0-0 0000 -0-0 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 xxxx xxxx uuuu uuuu 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 xxxx xxxx uuuu uuuu 10h t1con t1ginv t1ge t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0000 0000 uuuu uuuu 11h tmr2 timer2 module register 0000 0000 0000 0000 12h t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 13h sspbuf synchronous serial port receive buffer/transmit register xxxx xxxx uuuu uuuu 14h sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 0000 0000 15h ccpr1l capture/compare/pwm register 1 (lsb) xxxx xxxx uuuu uuuu 16h ccpr1h capture/compare/pwm register 1 (msb) xxxx xxxx uuuu uuuu 17h ccp1con ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 19h txreg usart transmit data register 0000 0000 0000 0000 1ah rcreg usart receive data register 0000 0000 0000 0000 1bh (2) ccpr2l capture/compare/pwm register 2 (lsb) xxxx xxxx uuuu uuuu 1ch (2) ccpr2h capture/compare/pwm register 2 (msb) xxxx xxxx uuuu uuuu 1dh (2) ccp2con ? ? ccp2x ccp2y ccp2m3 ccp2m2 ccp2m1 ccp2m0 --00 0000 --00 0000 1eh adresh a/d result register high byte xxxx xxxx uuuu uuuu 1fh adcon0 adfm vcfg1 vcfg0 chs2 chs1 chs0 go/done adon 0000 0000 0000 0000 legend: - = unimplemented locations read as ? 0 ?, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented note 1: other (non power-up) resets include mclr reset and watchdog timer reset during normal operation. 2: pic16f914/917 only.
PIC16F917/916/914/913 ds41250d-page 18 preliminary ? 2005 microchip technology inc. table 2-2: PIC16F917/916/914/913 special function registers summary bank 1 addr name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por/bor reset value on all other resets (1) bank 1 80h indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx xxxx xxxx 81h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 82h pcl program counter?s (pc) least significant byte 0000 0000 0000 0000 83h status irp rp1 rp0 to pd zdcc 0001 1xxx 000q quuu 84h fsr indirect data memory address pointer xxxx xxxx uuuu uuuu 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 86h trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 1111 1111 87h trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 1111 1111 1111 1111 88h trisd (2) trisd7 trisd6 trisd5 trisd4 trisd3 trisd2 trisd1 trisd0 1111 1111 1111 1111 89h trise ? ? ? ? trise3 (5) trise2 (2) trise1 (2) trise0 (2) ---- 1111 ---- 1111 8ah pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 ---0 0000 8bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 8dh pie2 osfie c2ie c1ie lcdie ?lvdie ? ccp2ie 0000 -0-0 0000 -0-0 8eh pcon ? ? ?sboren ? ?por bor ---1 --qq ---u --uu 8fh osccon ? ircf2 ircf1 ircf0 osts (4) hts lts scs -110 q000 -110 x000 90h osctune ? ? ? tun4 tun3 tun2 tun1 tun0 ---0 0000 ---u uuuu 91h ansel ans7 (3) ans6 (3) ans5 (3) ans4 ans3 ans2 ans1 ans0 1111 1111 1111 1111 92h pr2 timer2 period register 1111 1111 1111 1111 93h sspadd synchronous serial port (i 2 c mode) address register 0000 0000 0000 0000 94h sspstat smp cke d/a psr/w ua bf 0000 0000 0000 0000 95h wpub wpub7 wpub6 wpub5 wpub4 wpub3 wpub2 wpub1 wpub0 1111 1111 1111 1111 96h iocb iocb7 iocb6 iocb5 iocb4 ? ? ? ? 0000 ---- 0000 ---- 97h cmcon1 ? ? ? ? ? ? t1gss c2sync ---- --10 ---- --10 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg spbrg7 spbrg6 spbrg5 spbrg4 spbrg3 spbrg2 spbrg1 spbrg0 0000 0000 0000 0000 9ah ? unimplemented ? ? 9bh ? unimplemented ? ? 9ch cmcon0 c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0000 0000 0000 9dh vrcon vren ?vrr ? vr3 vr2 vr1 vr0 0-0- 0000 0-0- 0000 9eh adresl a/d result register low byte xxxx xxxx uuuu uuuu 9fh adcon1 ? adcs2 adcs1 adcs0 ? ? ? ? -000 ---- -000 --- legend: - = unimplemented locations read as ? 0 ?, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented note 1: other (non power-up) resets include mclr reset and watchdog timer reset during normal operation. 2: pic16f914/917 only. 3: pic16f914/917 only, forced ? 0 ? on pic16f913/916. 4: the value of the osts bit is dependent on the value of the configuration word (config) of the device. see section 4.0 ?clock sources? . 5: bit is read-only; trise = 1 always.
? 2005 microchip technology inc. preliminary ds41250d-page 19 PIC16F917/916/914/913 table 2-3: PIC16F917/916/914/913 special registers summary bank 2 addr name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por/bor reset value on all other resets (1) bank 2 100h indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx xxxx xxxx 101h tmr0 timer0 module register xxxx xxxx uuuu uuuu 102h pcl program counter?s (pc) least significant byte 0000 0000 0000 0000 103h status irp rp1 rp0 to pd zdcc 0001 1xxx 000q quuu 104h fsr indirect data memory address pointer xxxx xxxx uuuu uuuu 105h wdtcon ? ? ? wdtps3 wdtps2 wdtps1 wdtps0 swdten ---0 1000 ---0 1000 106h portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx uuuu uuuu 107h lcdcon lcden slpen werr vlcden cs1 cs0 lmux1 lmux0 0001 0011 0001 0011 108h lcdps wft biasmd lcda wa lp3 lp2 lp1 lp0 0000 0000 0000 0000 109h lvdcon ? ?irvstlvden ? lvdl2 lvdl1 lvdl0 --00 -100 --00 -100 10ah pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 ---0 0000 10bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 10ch eedatl eedatl7 eedatl6 eedatl5 eedatl4 eedatl3 eedatl2 eedatl1 eedatl0 0000 0000 0000 0000 10dh eeadrl eeadrl7 eeadrl6 eeadrl5 eeadrl4 eeadrl3 eeadrl2 eeadrl1 eeadrl0 0000 0000 0000 0000 10eh eedath ? ? eedath5 eedath4 eedath3 eedath2 eedath1 eedath0 --00 0000 --00 0000 10fh eeadrh ? ? ? eeadrh4 eeadrh3 eeadrh2 eeadrh1 eeadrh0 ---0 0000 ---0 0000 110h lcddata0 seg7 com0 seg6 com0 seg5 com0 seg4 com0 seg3 com0 seg2 com0 seg1 com0 seg0 com0 xxxx xxxx uuuu uuuu 111h lcddata1 seg15 com0 seg14 com0 seg13 com0 seg12 com0 seg11 com0 seg10 com0 seg9 com0 seg8 com0 xxxx xxxx uuuu uuuu 112h lcddata2 (2) seg23 com0 seg22 com0 seg21 com0 seg20 com0 seg19 com0 seg18 com0 seg17 com0 seg16 com0 xxxx xxxx uuuu uuuu 113h lcddata3 seg7 com1 seg6 com1 seg5 com1 seg4 com1 seg3 com1 seg2 com1 seg1 com1 seg0 com1 xxxx xxxx uuuu uuuu 114h lcddata4 seg15 com1 seg14 com1 seg13 com1 seg12 com1 seg11 com1 seg10 com1 seg9 com1 seg8 com1 xxxx xxxx uuuu uuuu 115h lcddata5 (2) seg23 com1 seg22 com1 seg21 com1 seg20 com1 seg19 com1 seg18 com1 seg17 com1 seg16 com1 xxxx xxxx uuuu uuuu 116h lcddata6 seg7 com2 seg6 com2 seg5 com2 seg4 com2 seg3 com2 seg2 com2 seg1 com2 seg0 com2 xxxx xxxx uuuu uuuu 117h lcddata7 seg15 com2 seg14 com2 seg13 com2 seg12 com2 seg11 com2 seg10 com2 seg9 com2 seg8 com2 xxxx xxxx uuuu uuuu 118h lcddata8 (2) seg23 com2 seg22 com2 seg21 com2 seg20 com2 seg19 com2 seg18 com2 seg17 com2 seg16 com2 xxxx xxxx uuuu uuuu 119h lcddata9 seg7 com3 seg6 com3 seg5 com3 seg4 com3 seg3 com3 seg2 com3 seg1 com3 seg0 com3 xxxx xxxx uuuu uuuu 11ah lcddata10 seg15 com3 seg14 com3 seg13 com3 seg12 com3 seg11 com3 seg10 com3 seg9 com3 seg8 com3 xxxx xxxx uuuu uuuu 11bh lcddata11 (2) seg23 com3 seg22 com3 seg21 com3 seg20 com3 seg19 com3 seg18 com3 seg17 com3 seg16 com3 xxxx xxxx uuuu uuuu 11ch lcdse0 (3) se7 se6 se5 se4 se3 se2 se1 se0 0000 0000 uuuu uuuu 11dh lcdse1 (3) se15 se14 se13 se12 se11 se10 se9 se8 0000 0000 uuuu uuuu 11eh lcdse2 (2,3) se23 se22 se21 se20 se19 se18 se17 se16 0000 0000 uuuu uuuu 11fh ? unimplemented ? ? legend: - = unimplemented locations read as ? 0 ?, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented note 1: other (non power-up) resets include mclr reset and watchdog timer reset during normal operation. 2: pic16f914/917 only. 3: this register is only initialized by a por or bor reset and is unchanged by other resets.
PIC16F917/916/914/913 ds41250d-page 20 preliminary ? 2005 microchip technology inc. table 2-4: PIC16F917/916/914/913 special function registers summary bank 3 addr name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por/bor reset value on all other resets (1) bank 3 180h indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx xxxx xxxx 181h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 182h pcl program counter (pc) least significant byte 0000 0000 0000 0000 183h status irp rp1 rp0 to pd zdcc 0001 1xxx 000q quuu 184h fsr indirect data memory address pointer xxxx xxxx uuuu uuuu 185h ? unimplemented ? ? 186h trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 1111 1111 187h ? unimplemented ? ? 188h ? unimplemented ? ? 189h ? unimplemented ? ? 18ah pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 ---0 0000 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 18ch eecon1 eepgd ? ? ? wrerr wren wr rd 0--- x000 0--- q000 18dh eecon2 eeprom control register 2 (not a physical register) ---- ---- ---- ---- legend: - = unimplemented locations read as ? 0 ?, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented note 1: other (non power-up) resets include mclr reset and watchdog timer reset during normal operation.
? 2005 microchip technology inc. preliminary ds41250d-page 21 PIC16F917/916/914/913 2.2.2.1 status register the status register, shown in register 2-1, contains: ? the arithmetic status of the alu ? the reset status ? the bank select bits for data memory (sram) the status register can be the destination for any instruction, like any other register. if the status register is the destination for an instruction that affects the z, dc or c bits, then the write to these three bits is disabled. these bits are set or cleared according to the device logic. furthermore, the to and pd bits are not writable. therefore, the result of an instruction with the status register as destination may be different than intended. for example, clrf status will clear the upper three bits and set the z bit. this leaves the status register as ? 000u u1uu ? (where u = unchanged). it is recommended, therefore, that only bcf, bsf, swapf and movwf instructions are used to alter the status register, because these instructions do not affect any status bits. for other instructions not affecting any status bits (see section 17.0 ?instruction set summary? ). register 2-1: status ? status register (address: 03h, 83h, 103h or 183h) note 1: the c and dc bits operate as a borrow and digit borrow out bit, respectively, in subtraction. see the sublw and subwf instructions for examples. r/w-0 r/w-0 r/w-0 r-1 r-1 r/w-x r/w-x r/w-x irp rp1 rp0 to pd zdc c bit 7 bit 0 bit 7 irp: register bank select bit (used for indirect addressing) 1 = bank 2, 3 (100h-1ffh) 0 = bank 0, 1 (00h-ffh) bit 6-5 rp<1:0> : register bank select bits (used for direct addressing) 00 = bank 0 (00h-7fh) 01 = bank 1 (80h-ffh) 10 = bank 2 (100h-17fh) 11 = bank 3 (180h-1ffh) bit 4 to : time-out bit 1 = after power-up, clrwdt instruction or sleep instruction 0 = a wdt time-out occurred bit 3 pd : power-down bit 1 = after power-up or by the clrwdt instruction 0 = by execution of the sleep instruction bit 2 z : zero bit 1 = the result of an arithmetic or logic operation is zero 0 = the result of an arithmetic or logic operation is not zero bit 1 dc : digit carry/bo rrow bit ( addwf , addlw,sublw,subwf instructions) (1) 1 = a carry-out from the 4th low-order bit of the result occurred 0 = no carry-out from the 4th low-order bit of the result bit 0 c : carry/bo rrow bit ( addwf , addlw, sublw, subwf instructions) (1) 1 = a carry-out from the most significant bit of the result occurred 0 = no carry-out from the most significant bit of the result occurred note 1: for borrow, the polarity is reversed. a subtraction is executed by adding the two?s complement of the second operand. for rotate ( rrf , rlf ) instructions, this bit is loaded with either the high or low-order bit of the source register. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
PIC16F917/916/914/913 ds41250d-page 22 preliminary ? 2005 microchip technology inc. 2.2.2.2 option register the option register is a readable and writable register, which contains various control bits to configure: ? tmr0/wdt prescaler ? external rb0/int interrupt ?tmr0 ? weak pull-ups on portb register 2-2: option_reg ? option register (address: 81h or 181h) note: to achieve a 1:1 prescaler assignment for tmr0, assign the prescaler to the wdt by setting psa bit to ? 1 ? (option_reg<3>). see section 5.4 ?prescaler? . r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg t0cs t0se psa ps2 ps1 ps0 bit 7 bit 0 bit 7 rbpu : portb pull-up enable bit 1 = portb pull-ups are disabled 0 = portb pull-ups are enabled by individual port latch values bit 6 intedg: interrupt edge select bit 1 = interrupt on rising edge of rb0/int/seg0 pin 0 = interrupt on falling edge of rb0/int/seg0 pin bit 5 t0cs: tmr0 clock source select bit 1 = transition on ra4/c1out/t0cki/seg4 pin 0 = internal instruction cycle clock (clko) bit 4 t0se: tmr0 source edge select bit 1 = increment on high-to-low transition on ra4/c1out/t0cki/seg4 pin 0 = increment on low-to-high transition on ra4/c1out/t0cki/seg4 pin bit 3 psa: prescaler assignment bit 1 = prescaler is assigned to the wdt 0 = prescaler is assigned to the timer0 module bit 2-0 ps<2:0>: prescaler rate select bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown 000 001 010 011 100 101 110 111 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 1 : 256 1 : 1 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 bit value tmr0 rate wdt rate
? 2005 microchip technology inc. preliminary ds41250d-page 23 PIC16F917/916/914/913 2.2.2.3 intcon register the intcon register is a readable and writable register, which contains the various enable and flag bits for tmr0 register overflow, portb change and external rb0/int/seg0 pin interrupts. register 2-3: intcon ? interrupt control register (address: 0bh, 8bh, 10bh or 18bh) note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global enable bit, gie (intcon<7>). user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-x gie peie t0ie inte rbie t0if intf rbif bit 7 bit 0 bit 7 gie: global interrupt enable bit 1 = enables all unmasked interrupts 0 = disables all interrupts bit 6 peie: peripheral interrupt enable bit 1 = enables all unmasked peripheral interrupts 0 = disables all peripheral interrupts bit 5 t0ie: tmr0 overflow interrupt enable bit 1 = enables the tmr0 interrupt 0 = disables the tmr0 interrupt bit 4 inte: rb0/int/seg0 external interrupt enable bit 1 = enables the rb0/int/seg0 external interrupt 0 = disables the rb0/int/sef0 external interrupt bit 3 rbie: portb change interrupt enable bit (1) 1 = enables the portb change interrupt 0 = disables the portb change interrupt bit 2 t0if: tmr0 overflow interrupt flag bit (2) 1 = tmr0 register has overflowed (must be cleared in software) 0 = tmr0 register did not overflow bit 1 intf: rb0/int/seg0 external interrupt flag bit 1 = the rb0/int/seg0 external interrupt occurred (must be cleared in software) 0 = the rb0/int/seg0 external interrupt did not occur bit 0 rbif: portb change interrupt flag bit 1 = when at least one of the portb <5:0> pins changed state (must be cleared in software) 0 = none of the portb <7:4> pins have changed state note 1: iocb register must also be enabled. 2: t0if bit is set when timer0 rolls over. timer0 is unchanged on reset and should be initialized before clearing t0if bit. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
PIC16F917/916/914/913 ds41250d-page 24 preliminary ? 2005 microchip technology inc. 2.2.2.4 pie1 register the pie1 register contains the interrupt enable bits, as shown in register 2-1. register 2-4: pie1 ? peripheral interrupt enable register 1 (address: 8ch) note: bit peie (intcon<6>) must be set to enable any peripheral interrupt. r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie bit 7 bit 0 bit 7 eeie: ee write complete interrupt enable bit 1 = enabled 0 = disabled bit 6 adie: a/d converter interrupt enable bit 1 = enabled 0 = disabled bit 5 rcie: usart receive interrupt enable bit 1 = enabled 0 = disabled bit 4 txie: usart transmit interrupt enable bit 1 = enabled 0 = disabled bit 3 sspie: synchronous serial port (ssp) interrupt enable bit 1 = enabled 0 = disabled bit 2 ccp1ie: ccp1 interrupt enable bit 1 = enabled 0 = disabled bit 1 tmr2ie: tmr2 to pr2 match interrupt enable bit 1 = enabled 0 = disabled bit 0 tmr1ie: tmr1 overflow interrupt enable bit 1 = enabled 0 = disabled legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. preliminary ds41250d-page 25 PIC16F917/916/914/913 2.2.2.5 pie2 register the pie2 register contains the interrupt enable bits, as shown in register 2-5. register 2-5: pie2 ? peripheral interrupt enable register 2 (address: 8dh) note: bit peie (intcon<6>) must be set to enable any peripheral interrupt. r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 u-0 r/w-0 osfie c2ie c1ie lcdie ?lvdie ? ccp2ie bit 7 bit 0 bit 7 osfie: oscillator fail interrupt enable bit 1 = enabled 0 =disabled bit 6 c2ie: comparator 2 interrupt enable bit 1 = enables comparator 2 interrupt 0 = disables comparator 2 interrupt bit 5 c1ie: comparator 1 interrupt enable bit 1 = enables comparator 1 interrupt 0 = disables comparator 1 interrupt bit 4 lcdie: lcd module interrupt enable bit 1 = lcd interrupt is enabled 0 = lcd interrupt is disabled bit 3 unimplemented: read as ? 0 ? bit 2 lvdie: low voltage detect interrupt enable bit 1 = enables lvd interrupt 0 = disables lvd interrupt bit 1 unimplemented: read as ? 0 ? bit 0 ccp2ie: ccp2 interrupt enable bit (only available in 16f914/917) 1 = enables the ccp2 interrupt 0 = disables the ccp2 interrupt legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
PIC16F917/916/914/913 ds41250d-page 26 preliminary ? 2005 microchip technology inc. 2.2.2.6 pir1 register the pir1 register contains the interrupt flag bits, as shown in register 2-6. register 2-6: pir1 ? peripheral interrupt request register 1 (address: 0ch) note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global enable bit, gie (intcon<7>). user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. r/w-0 r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 eeif adif rcif txif sspif ccp1if tmr2if tmr1if bit 7 bit 0 bit 7 eeif: ee write operation interrupt flag bit 1 = the write operation completed (must be cleared in software) 0 = the write operation has not completed or has not started bit 6 adif: a/d converter interrupt flag bit 1 = the a/d conversion completed (must be cleared in software) 0 = the a/d conversion is not complete bit 5 rcif: usart receive interrupt flag bit 1 = the usart receive buffer is full (cleared by reading rcreg) 0 = the usart receive buffer is not full bit 4 txif: usart transmit interrupt flag bit 1 = the usart transmit buffer is empty (cleared by writing to txreg) 0 = the usart transmit buffer is full bit 3 sspif: synchronous serial port (ssp) interrupt flag bit 1 = the transmission/reception is complete (must be cleared in software) 0 = waiting to transmit/receive bit 2 ccp1if: ccp1 interrupt flag bit capture mode 1 = a tmr1 register capture occurred (must be cleared in software) 0 = no tmr1 register capture occurred compare mode 1 = a tmr1 register compare match occurred (must be cleared in software) 0 = no tmr1 register compare match occurred pwm mode unused in this mode bit 1 tmr2if: tmr2 to pr2 interrupt flag bit 1 = a tmr2 to pr2 match occurred (must be cleared in software) 0 = no tmr2 to pr2 match occurred bit 0 tmr1if: tmr1 overflow interrupt flag bit 1 = the tmr1 register overflowed (must be cleared in software) 0 = the tmr1 register did not overflow legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. preliminary ds41250d-page 27 PIC16F917/916/914/913 2.2.2.7 pir2 register the pir2 register contains the interrupt flag bits, as shown in register 2-7. register 2-7: pir2 ? peripheral interrupt request register 2 (address: 0dh) note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global enable bit, gie (intcon<7>). user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. r/w-0 r/w-0 r-0 r-0 u-0 r/w-0 u-0 r/w-0 osfif c2if c1if lcdif ?lvdif ? ccp2if bit 7 bit 0 bit 7 osfif: oscillator fail interrupt flag bit 1 = system oscillator failed, clock input has changed to intosc (must be cleared in software) 0 = system clock operating bit 6 c2if: comparator 2 interrupt flag bit 1 = comparator output (c2out bit) has changed (must be cleared in software) 0 = comparator output (c2out bit) has not changed bit 5 c1if: comparator 1 interrupt flag bit 1 = comparator output (c1out bit) has changed (must be cleared in software) 0 = comparator output (c1out bit) has not changed bit 4 lcdif: lcd module interrupt bit 1 = lcd has generated an interrupt 0 = lcd has not generated an interrupt bit 3 unimplemented: read as ? 0 ? bit 2 lvdif: low voltage detect interrupt flag bit 1 = lvd has generated an interrupt 0 = lvd has not generated an interrupt bit 1 unimplemented: read as ? 0 ? bit 0 ccp2if: ccp2 interrupt flag bit (only available in 16f914/917) capture mode 1 = a tmr1 register capture occurred (must be cleared in software) 0 = no tmr1 register capture occurred compare mode 1 = a tmr1 register compare match occurred (must be cleared in software) 0 = no tmr1 register compare match occurred pwm mode unused in this mode legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
PIC16F917/916/914/913 ds41250d-page 28 preliminary ? 2005 microchip technology inc. 2.2.2.8 pcon register the power control (pcon) register (see table 17-2) contains flag bits to differentiate between a: ? power-on reset (por ) ? brown-out reset (bor ) ? watchdog timer reset (wdt) ? external mclr reset the pcon register also controls the software enable of the bor. the pcon register bits are shown in register 2-8. register 2-8: pcon ? power control register (address: 8eh) u-0 u-0 u-0 r/w-1 u-0 u-0 r/w-0 r/w-x ? ? ? sboren ? ?por bor bit 7 bit 0 bit 7-5 unimplemented: read as ? 0 ? bit 4 sboren : software bor enable bit (1) 1 = bor enabled 0 = bor disabled bit 3-2 unimplemented: read as ? 0 ? bit 1 por : power-on reset status bit 1 = no power-on reset occurred 0 = a power-on reset occurred (must be set in software after a power-on reset occurs) bit 0 bor : brown-out reset status bit 1 = no brown-out reset occurred 0 = a brown-out reset occurred (must be set in software after a brown-out reset occurs) note 1: boren<1:0> = 01 in the configuration word register for this bit to control the bor . legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. preliminary ds41250d-page 29 PIC16F917/916/914/913 2.3 pcl and pclath the program counter (pc) is 13 bits wide. the low byte comes from the pcl register, which is a readable and writable register. the high byte (pc<12:8>) is not directly readable or writable and comes from pclath. on any reset, the pc is cleared. figure 2-5 shows the two situations for the loading of the pc. the upper example in figure 2-5 shows how the pc is loaded on a write to pcl (pclath<4:0> pch). the lower example in figure 2-5 shows how the pc is loaded during a call or goto instruction (pclath<4:3> pch). figure 2-5: loading of pc in different situations 2.3.1 computed goto a computed goto is accomplished by adding an offset to the program counter ( addwf pcl ). when perform- ing a table read using a computed goto method, care should be exercised if the table location crosses a pcl memory boundary (each 256-byte block). refer to the application note an556, ?implementing a table read? (ds00556). 2.3.2 stack the PIC16F917/916/914/913 family has an 8-level x 13-bit wide hardware stack (see figures 2-1 and 2-2). the stack space is not part of either program or data space and the stack pointer is not readable or writable. the pc is pushed onto the stack when a call instruction is executed or an interrupt causes a branch. the stack is poped in the event of a return , retlw or a retfie instruction execution. pclath is not affected by a push or pop operation. the stack operates as a circular buffer. this means that after the stack has been pushed eight times, the ninth push overwrites the value that was stored from the first push. the tenth push overwrites the second push (and so on). 2.4 program memory paging all PIC16F917/916/914/913 devices are capable of addressing a continuous 8k word block of program memory. the call and goto instructions provide only 11 bits of address to allow branching within any 2k pro- gram memory page. when doing a call or goto instruction, the upper 2 bits of the address are provided by pclath<4:3>. when doing a call or goto instruc- tion, the user must ensure that the page select bits are programmed so that the desired program memory page is addressed. if a return from a call instruction (or interrupt) is executed, the entire 13-bit pc is poped off the stack. therefore, manipulation of the pclath<4:3> bits is not required for the return instructions (which pops the address from the stack). example 2-1 shows the calling of a subroutine in page 1 of the program memory. this example assumes that pclath is saved and restored by the interrupt service routine (if interrupts are used). example 2-1: call of a subroutine in page 1 from page 0 pc 12 8 7 0 5 pclath<4:0> pclath instruction wit h alu result goto , call opcode<10:0> 8 pc 12 11 10 0 11 pclath<4:3> pch pcl 87 2 pclath pch pcl pcl a s destinatio n note 1: there are no status bits to indicate stack overflow or stack underflow conditions. 2: there are no instructions/mnemonics called push or pop. these are actions that occur from the execution of the call , return , retlw and retfie instruc- tions or the vectoring to an interrupt address. note: the contents of the pclath register are unchanged after a return or retfie instruction is executed. the user must rewrite the contents of the pclath regis- ter for any subsequent subroutine calls or goto instructions. org 0x500 bcf pclath,4 bsf pclath,3 ;select page 1 ;(800h-fffh) call sub1_p1 ;call subroutine in : ;page 1 (800h-fffh) : org 0x900 ;page 1 (800h-fffh) sub1_p1 : ;called subroutine ;page 1 (800h-fffh) : return ;return to ;call subroutine ;in page 0 ;(000h-7ffh)
PIC16F917/916/914/913 ds41250d-page 30 preliminary ? 2005 microchip technology inc. 2.5 indirect addressing, indf and fsr registers the indf register is not a physical register. addressing the indf register will cause indirect addressing. indirect addressing is possible by using the indf register. any instruction using the indf register actually accesses data pointed to by the file select register (fsr). reading indf itself indirectly will produce 00h. writing to the indf register indirectly results in a no operation (although status bits may be affected). an effective 9-bit address is obtained by concatenating the 8-bit fsr register and the irp bit (status<7>), as shown in figure 2-6. a simple program to clear ram location 20h-2fh using indirect addressing is shown in example 2-2. example 2-2: indirect addressing figure 2-6: direct/indirect addressing PIC16F917/916/914/913 movlw 0x20 ;initialize pointer movwf fsr ;to ram nextclrf indf ;clear indf register incf fsr ;inc pointer btfss fsr,4 ;all done? goto next ;no clear next continue ;yes continue note: for memory map detail, see figures 2-3 and 2-4. data memory indirect addressing direct addressing bank select location select rp1 rp0 6 0 from opcode irp file select register 7 0 bank select location select 00 01 10 11 180h 1ffh 00h 7fh bank 0 bank 1 bank 2 bank 3
? 2005 microchip technology inc. preliminary ds41250d-page 31 PIC16F917/916/914/913 3.0 i/o ports this device includes four 8-bit port registers along with their corresponding tris registers and one four bit port: ? porta and trisa ? portb and trisb ? portc and trisc ? portd and trisd ? porte and trise porta, portb, portc and re3/mclr /v pp are implemented on all devices. portd and re<2:0> are implemented only on the pic16f914 and PIC16F917. 3.1 porta and trisa registers porta is a 8-bit wide, bidirectional port. the corresponding data direction register is trisa (register 3-2). setting a trisa bit (= 1 ) will make the corresponding porta pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisa bit (= 0 ) will make the corresponding porta pin an output (i.e., put the contents of the output latch on the selected pin). example 3-1 shows how to initialize porta. five of the pins of porta can be configured as analog inputs. these pins, ra5 and ra<3:0>, are configured as analog inputs on device power-up and must be reconfigured by the user to be used as i/o?s. this is done by writing the appropriate values to the cmcon0 and ansel registers (see example 3-1). reading the porta register (register 3-1) reads the status of the pins, whereas writing to it will write to the port latch. all write operations are read-modify-write operations. therefore, a write to a port implies that the port pins are read, this value is modified and then written to the port data latch. the trisa register controls the direction of the porta pins, even when they are being used as analog inputs. the user must ensure the bits in the trisa register are maintained set when using them as analog inputs. i/o pins configured as analog input always read ? 0 ?. example 3-1: initializing porta note 1: the cmcon0 (9ch) register must be initialized to configure an analog channel as a digital input. pins configured as analog inputs will read ? 0 ?. 2: analog lines that carry lcd signals (i.e., segx, comy, where x and y are segment and common identifiers) are shown as direct connections to the device pins. the signals are outputs from the lcd module and may be tri-stated, depending on the configuration of the lcd module. bcf status,rp0 ;bank 0 bcf status,rp1 ; clrf porta ;init porta bsf status,rp0 ;bank 1 bcf status,rp1 ; movlw 07h ;set ra<2:0> to movwf cmcon0 ;digital i/o clf ansel ;make all porta i/o movlw f0h ;set ra<7:4> as inputs movwf trisa ;and set ra<3:0> ; as outputs bcf status,rp0 ;bank 0 bcf status,rp1 ;
PIC16F917/916/914/913 ds41250d-page 32 preliminary ? 2005 microchip technology inc. register 3-1: porta ? porta register (address: 05h) register 3-2: trisa ? porta tri-state register (address: 85h) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 bit 7 bit 0 bit 7-0 ra<7:0> : porta i/o pin bits 1 = port pin is >v ih 0 = port pin is : porta tri-state control bits 1 = porta pin configured as an input (tri-stated) 0 = porta pin configured as an output note: trisa<7:6> always reads ? 1 ? in xt, hs and lp osc modes. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. preliminary ds41250d-page 33 PIC16F917/916/914/913 3.1.1 pin descriptions and diagrams each porta pin is multiplexed with other functions. the pins and their combined functions are briefly described here. for specific information about individual functions, refer to the appropriate section in this data sheet. 3.1.1.1 ra0/an0/c1-/seg12 figure 3-1 shows the diagram for this pin. the ra0/an0/c1-/seg12 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the a/d ? an analog input for comparator 1 ? an analog output for the lcd figure 3-1: block diagra m of ra0/an0/c1-/seg12 q d q ck data latch tris latch rd trisa rd porta analog input or i/o pin q d q ck ttl input buffer v dd to a/d converter or comparator seg12 se12 and lcden se12 and lcden data bus wr porta wr trisa se12 and lcden
PIC16F917/916/914/913 ds41250d-page 34 preliminary ? 2005 microchip technology inc. 3.1.1.2 ra1/an1/c2-/seg7 figure 3-2 shows the diagram for this pin. the ra1/an1/c2-/seg7 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the a/d ? an analog input for comparator 2 ? an analog output for the lcd figure 3-2: block diagra m of ra1/an1/c2-/seg7 q d q ck data latch tris latch rd trisa rd porta q d q ck to a/d converter or comparator seg7 data bus wr porta wr trisa analog input or i/o pin ttl input buffer v dd se7 and lcden se7 and lcden se7 and lcden
? 2005 microchip technology inc. preliminary ds41250d-page 35 PIC16F917/916/914/913 3.1.1.3 ra2/an2/c2+/v ref -/com2 figure 3-3 shows the diagram for this pin. the ra2/an2/c2+/v ref -/com2 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the a/d ? an analog input for comparator 2 ? a voltage reference input for the a/d ? an analog output for the lcd figure 3-3: block diag ram of ra2/an2/c2+/v ref -/com2 q d q ck data latch tris latch rd trisa rd porta q d q ck to a/d converter or comparator com2 data bus wr porta wr trisa to a/d module v ref - input analog input or i/o pin ttl input buffer v dd lcden and lmux<1:0> = 1x lcden and lmux<1:0> = 1x lcden and lmux<1:0> = 1x
PIC16F917/916/914/913 ds41250d-page 36 preliminary ? 2005 microchip technology inc. 3.1.1.4 ra3/an3/c1+/v ref +/com3/seg15 figure 3-4 shows the diagram for this pin. the ra3/an3/c1+/v ref +/com3/seg15 pin is configurable to function as one of the following: ? a general purpose input ? an analog input for the a/d ? an analog input from comparator 1 ? a voltage reference input for the a/d ? analog outputs for the lcd figure 3-4: block diag ram of ra3/an3/c1+/v ref +/com3/seg15 q d q ck data latch tris latch rd trisa rd porta v ss q d q ck ttl input buffer to a/d converter or comparator com3 (1) or seg15 data bus wr porta wr trisa to a / d m o d u l e v ref + input note 1: pic16f913/916 only. 2: for the pic16f913/916, the lcdmode_en = lcden and (se15 or lmux<1:0> = 11 ). for the pic16f914/917, the lcdmode_en = lcden and se15. q q v dd lcdmode_en (2) analog input or i/o pin lcdmode_en (2) lcdmode_en (2)
? 2005 microchip technology inc. preliminary ds41250d-page 37 PIC16F917/916/914/913 3.1.1.5 ra4/c1out/t0cki/seg4 figure 3-5 shows the diagram for this pin. the ra4/c1out/t0cki/seg4 pin is configurable to function as one of the following: ? a general purpose i/o ? a digital output from comparator 1 ? a clock input for tmr0 ? an analog output for the lcd figure 3-5: block diagram of ra4/c1out/t0cki/seg4 c1out cm<2:0> = 110 or 101 0 1 schmitt trigger q d q ck data latch tris latch rd trisa rd porta v ss v dd q d q ck t0cki data bus wr porta wr trisa seg4 analog input or i/o pin ttl input buffer se4 and lcden se4 and lcden se4 and lcden se4 and lcden
PIC16F917/916/914/913 ds41250d-page 38 preliminary ? 2005 microchip technology inc. 3.1.1.6 ra5/an4/c2out/ss /seg5 figure 3-6 shows the diagram for this pin. the ra5/an4/c2out/ss /seg5 pin is configurable to function as one of the following: ? a general purpose i/o ? a digital output from comparator 2 ? a slave select input ? an analog output for the lcd ? an analog input for the a/d figure 3-6: block diagra m of ra5/an4/c2out/ss /seg5 an4 rd trisa rd porta ttl input buffer seg5 se5 and lcden data bus wr porta wr trisa to s s input analog input or se5 and lcden c2out cm<2:0> = 110 or 101 0 1 q d q ck data latch v ss v dd q d q ck i/o pin tris latch se5 and lcden
? 2005 microchip technology inc. preliminary ds41250d-page 39 PIC16F917/916/914/913 3.1.1.7 ra6/osc2/clko/t1oso figure 3-7 shows the diagram for this pin. the ra6/osc2/clko/t1oso pin is configurable to function as one of the following: ? a general purpose i/o ? a crystal/resonator connection ? a clock output ? a tmr1 oscillator connection figure 3-7: block diagra m of ra6/osc2/clko/t1oso clko (f osc /4) f osc = 1x1 rd porta ttl input buffer data bus wr porta wr trisa f osc = 00x , 010 f osc = 00x , 010 ra6/osc2/ oscillator circuit from osc1 clko/t1oso pin rd trisa 0 1 q d q ck data latch v ss v dd q d q ck tris latch or t1oscen or t1oscen
PIC16F917/916/914/913 ds41250d-page 40 preliminary ? 2005 microchip technology inc. 3.1.1.8 ra7/osc1/clki/t1osi figure 3-8 shows the diagram for this pin. the ra7/osc1/clki/t1osi pin is configurable to function as one of the following: ? a general purpose i/o ? a crystal/resonator connection ? a clock input ? a tmr1 oscillator connection figure 3-8: block diagra m of ra7/osc1/clki/t1osi table 3-1: summary of registers associated with porta address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 05h porta ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 xxxx xxxx uuuu uuuu 10h t1con t1ginv t1ge t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0000 0000 uuuu uuuu 14h sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 0000 0000 1fh adcon0 adfm vcfg1 vcfg0 chs2 chs1 chs0 go/done adon 0000 0000 0000 0000 81h/181h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 91h ansel ans7 ans6 ans5 ans4 ans3 ans2 ans1 ans0 1111 1111 1111 1111 9ch cmcon0 c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0000 0000 0000 107h lcdcon lcden slpen werr vlcden cs1 cs0 lmux1 lmux0 0001 0011 0001 0011 11ch lcdse0 (1) se7 se6 se5 se4 se3 se2 se1 se0 0000 0000 uuuu uuuu 11dh lcdse1 (1) se15 se14 se13 se12 se11 se10 se9 se8 0000 0000 uuuu uuuu legend: x = unknown, u = unchanged, - = unimplemented locations read as ? 0 ?. shaded cells are not used by porta. note 1: this register is only initialized by a por or bor reset and is unchanged by other resets. q d q ck data latch tris latch rd trisa rd porta q d q ck ttl input buffer data bus wr porta wr trisa f osc = 10x f osc = 10x ra7/osc1/ v dd clki/t1osi pin oscillator circuit from osc1 f osc = 011
? 2005 microchip technology inc. preliminary ds41250d-page 41 PIC16F917/916/914/913 3.2 portb and trisb registers portb is a general purpose i/o port with similar functionality as the pic16f77. all portb pins can have a weak pull-up feature, and portb<7:4> implements an interrupt-on-input change function. portb is also used for the serial flash programming interface. example 3-2: initializing portb 3.3 additional portb pin functions rb<7:6> are used as data and clock signals, respectively, for both serial programming and the in-circuit debugger features on the device. also, rb0 can be configured as an external interrupt input. 3.3.1 weak pull-ups each of the portb pins has an individually configurable internal weak pull-up. control bits wpub<7:0> enable or disable each pull-up. refer to register 3-6. each weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on a power-on reset by the rbpu bit (option_reg<7>). 3.3.2 interrupt-on-change four of the portb pins are individually configurable as an interrupt-on-change pin. control bits iocb<7:4> enable or disable the interrupt function for each pin. refer to register 3-5. the interrupt-on-change feature is disabled on a power-on reset. for enabled interrupt-on-change pins, the values are compared with the old value latched on the last read of portb. the ?mismatch? outputs of the last read are or?d together to set the portb change interrupt flag bit (rbif) in the intcon register (register 2-3). this interrupt can wake the device from sleep. the user, in the interrupt service routine, clears the interrupt by: a) any read or write of portb. this will end the mismatch condition. b) clear the flag bit rbif. a mismatch condition will continue to set flag bit rbif. reading or writing portb will end the mismatch con- dition and allow flag bit rbif to be cleared. the latch holding the last read value is not affected by a mclr nor brown-out reset. after these resets, the rbif flag will continue to be set if a mismatch is present. note: analog lines that carry lcd signals (i.e., segx, comy, where x and y are seg- ment and common identifiers) are shown as direct connections to the device pins. the signals are outputs from the lcd module and may be tri-stated, depending on the configuration of the lcd module. bcf status,rp0 ;bank 0 bcf status,rp1 ; clrf portb ;init portb bsf status,rp0 ;bank 1 bcf status,rp1 ; movlw ffh ;set rb<7:0> as inputs movwf trisb ; bcf status,rp0 ;bank 0 bcf status,rp1 ; note: if a change on the i/o pin should occur when the read operation is being executed (start of the q2 cycle), then the rbif interrupt flag may not get set. furthermore, since a read or write on a port affects all bits of that port, care must be taken when using multiple pins in interrupt-on-change mode. changes on one pin may not be seen while servicing changes on another pin.
PIC16F917/916/914/913 ds41250d-page 42 preliminary ? 2005 microchip technology inc. register 3-3: portb ? portb register (address: 06h or 106h) register 3-4: trisb ? portb tri-state register (address: 86h, 186h) register 3-5: iocb ? portb interrupt-on-change re gister (address: 96h) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 bit 7 bit 0 bit 7-0 rb<7:0> : portb i/o pin bits 1 = port pin is >v ih 0 = port pin is : portb tri-state control bits 1 = portb pin configured as an input (tri-stated) 0 = portb pin configured as an output note: trisb<7:6> always reads ? 1 ? in xt, hs and lp osc modes. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 iocb7 iocb6 iocb5 iocb4 ? ? ? ? bit 7 bit 0 bit 7-4 iocb<7:4>: interrupt-on-change bits 1 = interrupt-on-change enabled 0 = interrupt-on-change disabled bit 3-0 unimplemented: read as ? 0 ? legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. preliminary ds41250d-page 43 PIC16F917/916/914/913 register 3-6: wpub ? weak pull-up register (address: 95h) r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 wpub7 wpub6 wpub5 wpub4 wpub3 wpub2 wpub1 wpub0 bit 7 bit 0 bit 7-0 wpub<7:0>: weak pull-up register bits 1 = pull-up enabled 0 = pull-up disabled note 1: global rbp u must be enabled for individual pull-ups to be enabled. 2: the weak pull-up device is automatically disabled if the pin is in output mode (trisb<7:0> = 0 ). legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
PIC16F917/916/914/913 ds41250d-page 44 preliminary ? 2005 microchip technology inc. 3.3.3 pin descriptions and diagrams each portb pin is multiplexed with other functions. the pins and their combined functions are briefly described here. for specific information about individual functions such as the lcd or interrupts, refer to the appropriate section in this data sheet. 3.3.3.1 rb0/int/seg0 figure 3-9 shows the diagram for this pin. the rb0/int/seg0 pin is configurable to function as one of the following: ? a general purpose i/o ? an external edge triggered interrupt ? an analog output for the lcd 3.3.3.2 rb1/seg1 figure 3-9 shows the diagram for this pin. the rb1/seg1 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog output for the lcd 3.3.3.3 rb2/seg2 figure 3-9 shows the diagram for this pin. the rb2/seg2 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog output for the lcd 3.3.3.4 rb3/seg3 figure 3-9 shows the diagram for this pin. the rb3/seg3 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog output for the lcd
? 2005 microchip technology inc. preliminary ds41250d-page 45 PIC16F917/916/914/913 figure 3-9: block diagram of rb<3:0> q d ck data latch tris latch rd trisb rd portb q d ck ttl input buffer se<3:0> and lcden data bus wr portb wr trisb p v dd i/o pin v dd weak pull-up se<3:0> seg<3:0> int (2) schmitt trigger se0 and lcden rbpu (1) note 1: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit. 2: rb0 only. se<3:0> and lcden
PIC16F917/916/914/913 ds41250d-page 46 preliminary ? 2005 microchip technology inc. 3.3.3.5 rb4/com0 figure 3-10 shows the diagram for this pin. the rb4/com0 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog output for the lcd figure 3-10: block diagram of rb4/com0 from other set rbif rb<7:4> pins lcden com0 q d ck data latch tris latch rd trisb rd portb q d ck ttl input buffer lcden data bus wr portb wr trisb p v dd i/o pin v dd weak pull-up lcden rbpu (1) note 1: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit. d q en lcden f osc /4 q d en rd portb
? 2005 microchip technology inc. preliminary ds41250d-page 47 PIC16F917/916/914/913 3.3.3.6 rb5/com1 figure 3-11 shows the diagram for this pin. the rb5/com1 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog output for the lcd figure 3-11: block diagram of rb5/com1 from other set rbif rb<7:4> pins rd portb f osc /4 com1 q d ck data latch tris latch rd trisb rd portb q d ck d q en ttl input buffer data bus wr portb wr trisb p v dd i/o pin v dd weak pull-up lcden and lmux<1:0> 00 rbpu (1) note 1: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit. d q en lcden and lmux<1:0> 00 lcden and lcden and lmux<1:0> 00 lmux<1:0> 00
PIC16F917/916/914/913 ds41250d-page 48 preliminary ? 2005 microchip technology inc. 3.3.3.7 rb6/icspclk/icdck/seg14 figure 3-12 shows the diagram for this pin. the rb6/icspclk/icdck/seg14 pin is configurable to function as one of the following: ? a general purpose i/o ? an in-circuit serial programming? clock ? an icd clock i/o ? an analog output for the lcd figure 3-12: block diagram of rb6/icspclk/icdck/seg14 from other set rbif rb<7:4> pins f osc /4 rd portb program mode/icd pgc q d ck data latch tris latch rd trisb rd portb q d ck d q en ttl input buffer se14 and lcden data bus wr portb wr trisb p v dd i/o pin v dd weak pull-up se14 and lcden rbpu (1) note 1: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit. d q en program mode/icd seg14 schmitt trigger buffer se14 and lcden se14 and lcden
? 2005 microchip technology inc. preliminary ds41250d-page 49 PIC16F917/916/914/913 3.3.3.8 rb7/icspdat/icddat/seg13 figure 3-13 shows the diagram for this pin. the rb7/icspdat/icddat/seg13 pin is configurable to function as one of the following: ? a general purpose i/o ? an in-circuit serial programming? i/o ? an icd data i/o ? an analog output for the lcd figure 3-13: block diagram of rb7/icspdat/icddat/seg13 from other set rbif rb<7:4> pins f osc /4 rd portb pgd q d ck data latch tris latch rd trisb rd portb q d ck d q en ttl input buffer se13 and lcden data bus wr portb wr trisb p v dd i/o pin v dd weak pull-up se13 and lcden rbpu (1) note 1: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit. d q en port /program mode/icd seg13 schmitt trigger buffer se13 and lcden 1 0 0 1 pgd drven pgd se13 and lcden program mode/icd
PIC16F917/916/914/913 ds41250d-page 50 preliminary ? 2005 microchip technology inc. table 3-2: summary of registers associated with portb address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 06h/106h portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx uuuu uuuu 86h/186h trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 1111 1111 0bh/8bh/ 10bh/18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 95h wpub wpub7 wpub6 wpub5 wpub4 wpub3 wpub2 wpub1 wpub0 1111 1111 1111 1111 96h iocb iocb7 iocb6 iocb5 iocb4 ? ? ? ? 0000 ---- 0000 ---- 107h lcdcon lcden slpen werr vlcden cs1 cs0 lmux1 lmux0 0001 0011 0001 0011 11ch lcdse0 (1) se7 se6 se5 se4 se3 se2 se1 se0 0000 0000 uuuu uuuu 11dh lcdse1 (1) se15 se14 se13 se12 se11 se10 se9 se8 0000 0000 uuuu uuuu legend: x = unknown, u = unchanged, - = unimplemented locations read as ? 0 ?. shaded cells are not used by portb. note 1: this register is only initialized by a por or bor reset and is unchanged by other resets.
? 2005 microchip technology inc. preliminary ds41250d-page 51 PIC16F917/916/914/913 3.4 portc and trisc registers portc is an 8-bit bidirectional port. portc is multiplexed with several peripheral functions. portc pins have schmitt trigger input buffers. all portc pins have latch bits (portc register). they, when written, will modify the contents of the portc latch; thus, modifying the value driven out on a pin if the corresponding trisc bit is configured for output. example 3-3: initializing portc register 3-7: portc ? portc register (address: 07h) register 3-8: trisc ? portc tri-state register (address: 87h) note: analog lines that carry lcd signals (i.e., segx, vlcdy, where x and y are segment and lcd bias voltage identifiers) are shown as direct connections to the device pins. the signals are outputs from the lcd module and may be tri-stated, depending on the configuration of the lcd module. bcf status,rp0 ;bank 0 bcf status,rp1 ; clrf portc ;init portc bsf status,rp0 ;bank 1 bcf status,rp1 ; movlw ffh ;set rc<7:0> as inputs movwf trisc ; bcf status,rp0 ;bank 2 bsf status,rp1 ; clrf lcdcon ;disable vlcd<3:1> ;inputs on rc<2:0> bcf status,rp0 ;bank 0 bcf status,rp1 ; r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 bit 7 bit 0 bit 7-0 rc<7:0> : portc i/o pin bits 1 = port pin is >v ih 0 = port pin is : portc tri-state control bits 1 = portc pin configured as an input (tri-stated) 0 = portc pin configured as an output note: trisc<7:6> always reads ? 1 ? in xt, hs and lp osc modes. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
PIC16F917/916/914/913 ds41250d-page 52 preliminary ? 2005 microchip technology inc. 3.4.1 pin descriptions and diagrams each portc pin is multiplexed with other functions. the pins and their combined functions are briefly described here. for specific information about individual functions such as the lcd or ssp, refer to the appropriate section in this data sheet. 3.4.1.1 rc0/vlcd1 figure 3-14 shows the diagram for this pin. the rc0/vlcd1 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the lcd bias voltage 3.4.1.2 rc1/vlcd2 figure 3-15 shows the diagram for this pin. the rc1/vlcd2 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the lcd bias voltage 3.4.1.3 rc2/vlcd3 figure 3-16 shows the diagram for this pin. the rc2/vlcd3 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the lcd bias voltage figure 3-14: block di agram of rc0/vlcd1 rd portc vlcd1 rc0/vlcd1 schmitt trigger v dd q d ck data latch tris latch rd trisc data bus wr portc wr trisc q d ck q q (vlcden and lmux<1:0> 00 ) (vlcden and lmux<1:0> 00) pin
? 2005 microchip technology inc. preliminary ds41250d-page 53 PIC16F917/916/914/913 figure 3-15: block di agram of rc1/vlcd2 figure 3-16: block di agram of rc2/vlcd3 rd portc vlcd2 rc1/vlcd2 schmitt trigger v dd q d ck data latch tris latch rd trisc data bus wr portc wr trisc q d ck q q (vlcden and lmux<1:0> 00 ) (vlcden and lmux<1:0> 00 ) pin rd portc vlcd3 rc2/vlcd3 schmitt trigger v dd q d ck data latch tris latch rd trisc data bus wr portc wr trisc q d ck q q vlcden vlcden pin
PIC16F917/916/914/913 ds41250d-page 54 preliminary ? 2005 microchip technology inc. 3.4.1.4 rc3/seg6 figure 3-17 shows the diagram for this pin. the rc3/seg6 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog output for the lcd figure 3-17: block di agram of rc3/seg6 rd portc seg6 and lcden rc3/seg6 schmitt trigger v dd q d ck data latch tris latch rd trisc data bus wr portc wr trisc q d ck q q se6 and lcden se6 and lcden pin
? 2005 microchip technology inc. preliminary ds41250d-page 55 PIC16F917/916/914/913 3.4.1.5 rc4/t1g /sdo/seg11 figure 3-18 shows the diagram for this pin. the rc4//t1g /sdo/seg11pin is configurable to function as one of the following: ? a general purpose i/o ? a tmr1 gate input ? a serial data output ? an analog output for the lcd figure 3-18: block diagram of rc4/t1g /sdo/seg11 sdo port/sdo select rd portc data bus wr portc wr trisc rc4/t1g / rd trisc 1 0 q d q ck data latch v ss v dd q d q ck tris latch schmitt trigger se11 and lcden timer1 gate seg11 se11 and lcden pin sdo/seg1 1
PIC16F917/916/914/913 ds41250d-page 56 preliminary ? 2005 microchip technology inc. 3.4.1.6 rc5/t1cki/ccp1/seg10 figure 3-19 shows the diagram for this pin. the rc5/t1cki/ccp1/seg10 pin is configurable to function as one of the following: ? a general purpose i/o ?a tmr1 clock input ? a capture input, compare output or pwm output ? an analog output for the lcd figure 3-19: block diagram of rc5/t1cki/ccp1/seg10 ccp1 data out (port/ccp1 select) and ccpmx rd portc data bus wr portc wr trisc rc5/t1cki/ rd trisc 1 0 q d q ck data latch v ss v dd q d q ck tris latch schmitt trigger se10 and lcden timer1 gate seg10 se10 and lcden pin ccp1/seg1 0
? 2005 microchip technology inc. preliminary ds41250d-page 57 PIC16F917/916/914/913 3.4.1.7 rc6/tx/ck/sck/scl/seg9 figure 3-20 shows the diagram for this pin. the rc6/tx/ck/sck/scl/seg9 pin is configurable to function as one of the following: ? a general purpose i/o ? an asynchronous serial output ? a synchronous clock i/o ? a spi clock i/o ?an i 2 c data i/o ? an analog output for the lcd figure 3-20: block diagram of rc6/tx/ck/sck/scl/seg9 tx/ck data out i 2 c ? data out rd portc data bus wr portc wr trisc rc6/tx/ rd trisc 3 1 q d q ck data latch v ss v dd q d q ck tris latch schmitt trigger se9 and lcden ck/scl/sck input seg9 se9 and lcden 0 port/scen/ssp mode select (1) scen or i 2 c ? drive note 1: if all three data output sources are enabled, the following priority order will be used: ? usart data ? ssp data ?port data 2 sck data out pin ck/sck/ scl/seg 9
PIC16F917/916/914/913 ds41250d-page 58 preliminary ? 2005 microchip technology inc. 3.4.1.8 rc7/rx/dt/sdi/sda/seg8 figure 3-21 shows the diagram for this pin. the rc7/rx/dt/sdi/sda/seg8 pin is configurable to function as one of the following: ? a general purpose i/o ? an asynchronous serial input ? a synchronous serial data i/o ? a spi data i/o ?an i 2 c data i/o ? an analog output for the lcd figure 3-21: block diagram of rc7/rx/dt/sdi/sda/seg8 data bus wr portc wr trisc rd portc rx/sdi input seg8 0 1 i 2 c ? data out schmitt trigger rc7/rx/dt/ v dd data latch tris latch q d q ck q d q ck i 2 c ? drive se8 and lcden rd trisc port/(scen or i 2 c ? ) select scen/i 2 c ? mode select (1) dt data out 1 0 or scen drive se8 and lcden note 1: if ssp and usart outputs are both enabled, the usart data output will have priority over the ssp data output. both ssp and usart data outputs will have priority over the port data output. pin sdi/sda/ seg8
? 2005 microchip technology inc. preliminary ds41250d-page 59 PIC16F917/916/914/913 table 3-3: summary of registers associated with portc address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 07h portc rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 xxxx xxxx uuuu uuuu 10h t1con t1ginv t1ge t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0000 0000 uuuu uuuu 14h sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 0000 0000 17h ccp1con ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 87h trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 1111 1111 1111 1111 107h lcdcon lcden slpen werr vlcden cs1 cs0 lmux1 lmux0 0001 0011 0001 0011 11ch lcdse0 (1) se7 se6 se5 se4 se3 se2 se1 se0 0000 0000 uuuu uuuu 11dh lcdse1 (1) se15 se14 se13 se12 se11 se10 se9 se8 0000 0000 uuuu uuuu legend: x = unknown, u = unchanged, - = unimplemented locations read as ? 0 ?. shaded cells are not used by portc. note 1: this register is only initialized by a por or bor reset and is unchanged by other resets.
PIC16F917/916/914/913 ds41250d-page 60 preliminary ? 2005 microchip technology inc. 3.5 portd and trisd registers portd is an 8-bit port with schmitt trigger input buffers. each pin is individually configured as an input or output. portd is only available on the pic16f914 and PIC16F917. example 3-4: initializing portd register 3-9: portd ? portd register (address: 08h) register 3-10: trisd ? portd tri-state register (address: 88h) note: analog lines that carry lcd signals (i.e., segx, comy, where x and y are seg- ment and common identifiers) are shown as direct connections to the device pins. the signals are outputs from the lcd module and may be tri-stated, depending on the configuration of the lcd module. bcf status,rp0 ;bank 0 bcf status,rp1 ; clrf portd ;init portd bsf status,rp0 ;bank 1 bcf status,rp1 ; movlw ffh ;set rd<7:0> as inputs movwf trisd ; bcf status,rp0 ;bank 0 bcf status,rp1 ; r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 bit 7 bit 0 bit 7-0 rd<7:0> : portd i/o pin bits 1 = port pin is >v ih 0 = port pin is : portd tri-state control bits 1 = portd pin configured as an input (tri-stated) 0 = portd pin configured as an output note: trisd<7:6> always reads ? 1 ? in xt, hs and lp osc modes. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. preliminary ds41250d-page 61 PIC16F917/916/914/913 3.5.1 pin descriptions and diagrams each portd pin is multiplexed with other functions. the pins and their combined functions are briefly described here. for specific information about individual functions such as the comparator or the a/d, refer to the appropriate section in this data sheet. 3.5.1.1 rd0/com3 figure 3-22 shows the diagram for this pin. the rd0/com3 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the a/d 3.5.1.2 rd1 figure 3-23 shows the diagram for this pin. the rd1 pin is configurable to function as one of the following: ? a general purpose i/o 3.5.1.3 rd2/ccp2 figure 3-24 shows the diagram for this pin. the rd2/ccp2 pin is configurable to function as one of the following: ? a general purpose i/o ? a capture input, compare output or pwm output 3.5.1.4 rd3/seg16 figure 3-25 shows the diagram for this pin. the rd3/seg16 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog output for the lcd 3.5.1.5 rd4/seg17 figure 3-25 shows the diagram for this pin. the rd4/seg17 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog output for the lcd 3.5.1.6 rd5/seg18 figure 3-25 shows the diagram for this pin. the rd5/seg18 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog output for the lcd 3.5.1.7 rd6/seg19 figure 3-25 shows the diagram for this pin. the rd6/seg19 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog output for the lcd 3.5.1.8 rd7/seg20 figure 3-25 shows the diagram for this pin. the rd7/seg20 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog output for the lcd
PIC16F917/916/914/913 ds41250d-page 62 preliminary ? 2005 microchip technology inc. figure 3-22: block di agram of rd0/com3 figure 3-23: block di agram of rd1 data bus wr portd wr trisd rd portd com3 schmitt trigger rd0/com3 v dd data latch tris latch q d q ck q d q ck lcden and lmux<1:0> = 11 rd trisd lcden and lmux<1:0> = 11 pin data bus wr portd wr trisd rd portd schmitt trigger rd1 pin v dd data latch tris latch q d q ck q d q ck rd trisd
? 2005 microchip technology inc. preliminary ds41250d-page 63 PIC16F917/916/914/913 figure 3-24: block di agram of rd2/ccp2 figure 3-25: block diag ram of rd<7:3> data bus wr portd wr trisd rd portd ccp2 input 0 1 (port/ccp2 select) and ccpmx ccp2 data out schmitt trigger rd2/ccp2 v dd data latch tris latch q d q ck q d q ck rd trisd pin data bus wr portd wr trisd rd portd seg<20:16> rd<7:3> pin v dd data latch tris latch q d q ck q d q ck se<20:16> and lcden rd trisd schmitt trigger se<20:16> and lcden
PIC16F917/916/914/913 ds41250d-page 64 preliminary ? 2005 microchip technology inc. table 3-4: summary of registers associated with portd address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 08h portd rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 xxxx xxxx uuuu uuuu 1dh (2) ccp2con ? ? ccp2x ccp2y ccp2m3 ccp2m2 ccp2m1 ccp2m0 --00 0000 --00 0000 88h trisd (2) trisd7 trisd6 trisd5 trisd4 trisd3 trisd2 trisd1 trisd0 1111 1111 1111 1111 107h lcdcon lcden slpen werr vlcden cs1 cs0 lmux1 lmux0 0001 0011 0001 0011 11eh lcdse2 (1,2) se23 se22 se21 se20 se19 se18 se17 se16 0000 0000 uuuu uuuu legend: x = unknown, u = unchanged, - = unimplemented locations read as ? 0 ?. shaded cells are not used by portc. note 1: this register is only initialized by a por or bor reset and is unchanged by other resets. 2: pic16f914/917 only.
? 2005 microchip technology inc. preliminary ds41250d-page 65 PIC16F917/916/914/913 3.6 porte and trise registers porte is a 4-bit port with schmitt trigger input buffers. re<2:0> are individually configured as inputs or out- puts. re3 is only available as an input if mclre is ? 0 ? in configuration word (register 16-1). re<2:0> are only available on the pic16f914 and PIC16F917. example 3-5: initializing porte register 3-11: porte ? porte register (address: 09h) register 3-12: trise ? porte tri-state register (address: 89h) note: analog lines that carry lcd signals (i.e., segx, where x are segment identifi- ers) are shown as direct connections to the device pins. the signals are outputs from the lcd module and may be tri-stated, depending on the configuration of the lcd module. bcf status,rp0 ;bank 0 bcf status,rp1 ; clrf porte ;init porte bsf status,rp0 ;bank 1 bcf status,rp1 ; movlw 0fh ;set re<3:0> as inputs movwf trise ; clrf ansel ;make re<2:0> as i/o?s bcf status,rp0 ;bank 0 bcf status,rp1 ; u-0 u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x ? ? ? ? re3 re2 re1 re0 bit 7 bit 0 bit 7-4 unimplemented: read as ? 0 ? bit 3-0 re<3:0> : porte i/o pin bits 1 = port pin is >v ih 0 = port pin is : data direction bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
PIC16F917/916/914/913 ds41250d-page 66 preliminary ? 2005 microchip technology inc. 3.6.1 pin descriptions and diagrams each porte pin is multiplexed with other functions. the pins and their combined functions are briefly described here. for specific information about individual functions such as the comparator or the a/d, refer to the appropriate section in this data sheet. 3.6.1.1 re0/an5/seg21 figure 3-26 shows the diagram for this pin. the re0/an5/seg21pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the a/d ? an analog output for the lcd 3.6.1.2 re1/an6/seg22 figure 3-26 shows the diagram for this pin. the re1/an6/seg22 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the a/d ? an analog output for the lcd 3.6.1.3 re2/an7/seg23 figure 3-26 shows the diagram for this pin. the re2/an7/seg23 pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the a/d ? an analog output for the lcd 3.6.1.4 re3/mclr /v pp figure 3-27 shows the diagram for this pin. the re3/mclr /v pp pin is configurable to function as one of the following: ? a digital input only ? as master clear reset with weak pull-up ? a programming voltage reference input figure 3-26: block diagram of re<2:0> data bus wr porte wr trise rd porte seg<23:21> schmitt trigger re<2:0> pin v dd data latch tris latch q d q ck q d q ck analog mode or rd trise an<7:5> se<23:21> and lcden se<23:21> and lcden
? 2005 microchip technology inc. preliminary ds41250d-page 67 PIC16F917/916/914/913 figure 3-27: block di agram of re3/mclr /v pp table 3-5: summary of registers associated with porte address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 09h porte ? ? ? ? re3 re2 re1 re0 ---- xxxx ---- uuuu 1fh adcon0 adfm vcfg1 vcfg0 chs2 chs1 chs0 go/done adon 0000 0000 0000 0000 89h trise ? ? ? ?trise3 (3) trise2 (2) trise1 (2) trise0 (2) ---- 1111 ---- 1111 91h ansel ans7 ans6 ans5 ans4 ans3 ans2 ans1 ans0 1111 1111 1111 1111 107h lcdcon lcden slpen werr vlcden cs1 cs0 lmux1 lmux0 0001 0011 0001 0011 11eh lcdse2 (1,2) se23 se22 se21 se20 se19 se18 se17 se16 0000 0000 uuuu uuuu legend: x = unknown, u = unchanged, - = unimplemented locations read as ? 0 ?. shaded cells are not used by portc. note 1: this register is only initialized by a por or bor reset and is unchanged by other resets. 2: pic16f914/917 only. 3: bit is read-only; trise = 1 always. hv detect mclr filter (1) re3/mclr /v pp re port mclr circuit programming mode data bus re tris m clre note 1: the mclr filter is bypassed in emulation mode. hv buffer schmitt trigger hv buffer schmitt trigger
PIC16F917/916/914/913 ds41250d-page 68 preliminary ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. preliminary ds41250d-page 69 PIC16F917/916/914/913 4.0 clock sources 4.1 overview the PIC16F917/916/914/913 has a wide variety of clock sources and selection features to allow it to be used in a wide range of applications while maximizing performance and minimizing power consumption. figure 4-1 illustrates a block diagram of the PIC16F917/916/914/913 clock sources. clock sources can be configured from external oscillators, quartz crystal resonators, ceramic resonators, and resistor-capacitor (rc) circuits. in addition, the system clock source can be configured from one of two internal oscillators, with a choice of speeds selectable via software. additional clock features include: ? selectable system clock source between external or internal via software. ? two-speed clock start-up mode, which minimizes latency between external oscillator start-up and code execution. ? fail-safe clock monitor (fscm) designed to detect a failure of the external clock source (lp, xt, hs, ec or rc modes) and switch to the internal oscillator. the PIC16F917/916/914/913 can be configured in one of eight clock modes. 1. ec ? external clock with i/o on ra6. 2. lp ? low-gain crystal or ceramic resonator oscillator mode. 3. xt ? medium-gain crystal or ceramic resonator oscillator mode. 4. hs ? high-gain crystal or ceramic resonator mode. 5. rc ? external resistor-capacitor (rc) with f osc /4 output on ra6. 6. rcio ? external resistor-capacitor with i/o on ra6. 7. intosc ? internal oscillator with f osc /4 output on ra6 and i/o on ra7. 8. intoscio ? internal oscillator with i/o on ra6 and ra7. clock source modes are configured by the fosc<2:0> bits in the configuration word register (see section 16.0 ?special features of the cpu? ). the internal clock can be generated by two oscillators. the hfintosc is a high-frequency calibrated oscillator. the lfintosc is a low-frequency uncalibrated oscillator. figure 4-1: PIC16F917/916/914/913 system clock block diagram (cpu and peripherals) osc1 osc2 sleep external oscillator lp, xt, hs, rc, rcio, ec system clock postscaler mux mux 8 mhz 4 mhz 2 mhz 1 mhz 500 khz 125 khz 250 khz ircf<2:0> 111 110 101 100 011 010 001 000 31 khz lcd module fosc<2:0> (configuration word) scs (osccon<0>) internal oscillator (osccon<6:4>) watchdog timer (wdt) fail-safe clock monitor (fscm) hfintosc 8 mhz lfintosc 31 khz power-up timer (pwrt)
PIC16F917/916/914/913 ds41250d-page 70 preliminary ? 2005 microchip technology inc. register 4-1: osccon ? oscillator control register (address: 8fh) u-0 r/w-1 r/w-1 r/w-0 r-q r-0 r-0 r/w-0 ? ircf2 ircf1 ircf0 osts (1) hts lts scs bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6-4 ircf<2:0>: internal oscillator frequency select bits 000 =31khz 001 =125khz 010 =250khz 011 =500khz 100 =1mhz 101 =2mhz 110 =4mhz 111 =8mhz bit 3 osts: oscillator start-up time-out status bit 1 = device is running from the external system clock defined by fosc<2:0> 0 = device is running from the internal system clock (hfintosc or lfintosc) bit 2 hts: hfintosc (high frequency ? 8 mhz to 125 khz) status bit 1 =hfintosc is stable 0 = hfintosc is not stable bit 1 lts: lfintosc (low frequency ? 31 khz) stable bit 1 = lfintosc is stable 0 = lfintosc is not stable bit 0 scs: system clock select bit 1 = internal oscillator is used for system clock 0 = clock source defined by fosc<2:0> note 1: the value of the osts bit on device power-up is dependent on the value of the configuration word (config) of the device. the value of the osts bit will be ? 0 ? on a device power-on reset (por) or any automatic clock switch, which may occur from two-speed start-up or fail-safe clock monitor, if the following conditions are true: osts = 0 if: fosc<2:0> = 000 (lp) or 001 (xt) or 010 (hs) and ieso = 1 or fscm = 1 (ieso will be enabled automatically if fscm is enabled) if any of the above conditions are not met, the value of the osts bit will be ? 1 ? on a device por. see section 4.6 ?two-speed clock start-up mode? and section 4.7 ?fail-safe clock monitor? for more details. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown q = value depends on condition
? 2005 microchip technology inc. preliminary ds41250d-page 71 PIC16F917/916/914/913 4.2 clock source modes clock source modes can be classified as external or internal. ? external clock modes rely on external circuitry for the clock source. examples are oscillator modules (ec mode), quartz crystal resonators or ceramic resonators (lp, xt and hs modes), and resistor-capacitor (rc mode) circuits. ? internal clock sources are contained internally within the PIC16F917/916/914/913. the PIC16F917/916/914/913 has two internal oscilla- tors: the 8 mhz high-frequency internal oscilla- tor (hfintosc) and 31 khz low-frequency internal oscillator (lfintosc). the system clock can be selected between external or internal clock sources via the system clock selection (scs) bit (see section 4.5 ?clock switching? ). 4.3 external clock modes 4.3.1 oscillator start-up timer (ost) if the PIC16F917/916/914/913 is configured for lp, xt or hs modes, the oscillator start-up timer (ost) counts 1024 oscillations from the osc1 pin, following a power-on reset (por), and the power-up timer (pwrt) has expired (if configured), or a wake-up from sleep. during this time, the program counter does not increment and program execution is suspended. the ost ensures that the oscillator circuit, using a quartz crystal resonator or ceramic resonator, has started and is providing a stable system clock to the PIC16F917/916/914/913. when switching between clock sources a delay is required to allow the new clock to stabilize. these oscillator delays are shown in table 4-1. 4.3.1.1 special case an exception to this is when the device is put to sleep while the following conditions are true: ? lp is the selected primary oscillator mode. ? t1oscen = 1 (timer1 oscillator is enabled). ?scs = 0 (oscillator mode is defined by fosc<2:0>). ? osts = 1 (device is running from primary system clock). for this case, the ost is not necessary after a wake-up from sleep, since timer1 continues to run during sleep and uses the same lp oscillator circuit as its clock source. for these devices, this case is typically seen when the lcd module is running during sleep. in applications where the osctune register is used to shift the f intosc frequency, the application should not expect the f intosc frequency to stabilize immediately. in this case, the frequency may shift gradually toward the new value. the time for this frequency shift is less than eight cycles of the base frequency. table 4-1 shows examples where the oscillator delay is invoked. in order to minimize latency between external oscillator start-up and code execution, the two-speed clock start-up mode can be selected (see section 4.6 ?two-speed clock start-up mode? ). note: when the ost is invoked, the wdog is held in reset, because the wdog ripple counter is used by the ost to perform the oscillator delay count. when the ost count has expired, the wdog will begin counting (if enabled).
PIC16F917/916/914/913 ds41250d-page 72 preliminary ? 2005 microchip technology inc. table 4-1: oscillator delay examples system clock source frequency switching from oscillator delay (t ost ) comments lfiosc 31 khz sleep 10 s internal delay following a wake-up from sleep mode or por, an internal delay is invoked to allow the memory bias to stabilize before program execution can begin. hfiosc 125 khz-8 mhz sleep 10 s internal delay following a wake-up from sleep mode or por, an internal delay is invoked to allow the memory bias to stabilize before program execution can begin. xt or hs 4-20 mhz intosc or sleep 1024 clock cycles following a change from intosc, an ost of 1024 cycles must occur. lp 32 khz intosc or sleep 1024 clock cycles following a change from intosc, an ost of 1024 cycles must occur. see section 4.3.1.1 ?special case? for special case conditions. lp with t1osc enabled 32 khz sleep 10 s internal delay following a wake-up from sleep mode, an internal delay is invoked to allow the memory bias to stabilize before program execution can begin. see section 4.3.1.1 ?special case? for details about this special case. ec, rc 0-20 mhz sleep 10 s internal delay following a wake-up from sleep mode or por, an internal delay is invoked to allow the memory bias to stabilize before program execution can begin. ec, rc 0-20 mhz lfiosc 10 s internal delay following a switch from a lfiosc or por, an internal delay is invoked to allow the memory bias to stabilize before program execution can begin.
? 2005 microchip technology inc. preliminary ds41250d-page 73 PIC16F917/916/914/913 4.3.2 ec mode the external clock (ec) mode allows an externally generated logic level as the system clock source. when operating in this mode, an external clock source is connected to the osc1 pin and the ra6 pin is available for general purpose i/o. figure 4-2 shows the pin connections for ec mode. the oscillator start-up timer (ost) is disabled when ec mode is selected. therefore, there is no delay in operation after a power-on reset (por) or wake-up from sleep. because the PIC16F917/916/914/913 design is fully static, stopping the external clock input will have the effect of halting the device while leaving all data intact. upon restarting the external clock, the device will resume operation as if no time had elapsed. figure 4-2: external clock (ec) mode operation 4.3.3 lp, xt, hs modes the lp, xt and hs modes support the use of quartz crystal resonators or ceramic resonators connected to the osc1 and osc2 pins (figures 4-3 and 4-4). the mode selects a low, medium or high gain setting of the internal inverter-amplifier to support various resonator types and speed. lp oscillator mode selects the lowest gain setting of the internal inverter-amplifier. lp mode current consumption is the least of the three modes. this mode is best suited to drive resonators with a low drive level specification, for example, tuning fork type crystals. xt oscillator mode selects the intermediate gain setting of the internal inverter-amplifier. xt mode current consumption is the medium of the three modes. this mode is best suited to drive resonators with a medium drive level specification, for example, low-frequency/at-cut quartz crystal resonators. hs oscillator mode selects the highest gain setting of the internal inverter-amplifier. hs mode current consumption is the highest of the three modes. this mode is best suited for resonators that require a high drive setting, for example, high-frequency/at-cut quartz crystal resonators or ceramic resonators. figures 4-3 and 4-4 show typical circuits for quartz crystal and ceramic resonators, respectively. ra6/osc2/clko/t1oso ra6 clock PIC16F917/916/914/913 internal f osc fosc<2:0> = 011 osc1/ clock clkin (external system) note: in the past, the sources for the lp oscilla- tor and timer1 oscillator have been sepa- rate circuits. in this family of devices, the lp oscillator and timer1 oscillator use the same oscillator circuitry. when using a device configured for the lp oscillator and with t1oscen = 1 , the source of the clock for each function comes from the same oscillator block.
PIC16F917/916/914/913 ds41250d-page 74 preliminary ? 2005 microchip technology inc. figure 4-3: quartz crystal operation (lp, xt or hs mode) figure 4-4: ceramic resonator operation (xt or hs mode) note 1: quartz crystal characteristics vary according to type, package and manufac- turer. the user should consult the manufacturer data sheets for specifica- tions and recommended application. 2: always verify oscillator performance over the v dd and temperature range that is expected for the application. note 1: a series resistor (r s ) may be required for quartz crystals with low drive level. 2: the value of r f varies with the oscillator mode selected (typically between 2 m to 10 m ) . 3: if using lp mode and t1osc in enable, the lp oscillator will continue to run during sleep. c1 c2 quartz osc2 r s (1) osc1 r f (2) sleep (3) to int. logic PIC16F917/916/914/913 crystal note 1: a series resistor (r s ) may be required for ceramic resonators with low drive level. 2: the value of r f varies with the oscillator mode selected (typically between 2 m to 10 m ) . 3: an additional parallel feedback resistor (r p ) may be required for proper ceramic resonator operation (typical value 1 m ). c1 c2 osc2 r s (1) osc1 r f (2) sleep to int. logic PIC16F917/916/914/913 r f (3) ceramic resonator
? 2005 microchip technology inc. preliminary ds41250d-page 75 PIC16F917/916/914/913 4.3.4 external rc modes the external resistor-capacitor (rc) modes support the use of an external rc circuit. this allows the designer maximum flexibility in frequency choice while keeping costs to a minimum when clock accuracy is not required. there are two modes, rc and rcio. in rc mode, the rc circuit connects to the osc1 pin. the osc2/clko pin outputs the rc oscillator frequency divided by 4. this signal may be used to provide a clock for external circuitry, synchronization, calibration, test or other application requirements. figure 4-5 shows the rc mode connections. figure 4-5: rc mode in rcio mode, the rc circuit is connected to the osc1 pin. the osc2 pin becomes an additional general purpose i/o pin. the i/o pin becomes bit 4 of porta (ra4). figure 4-6 shows the rcio mode connections. figure 4-6: rcio mode the rc oscillator frequency is a function of the supply voltage, the resistor (r ext ) and capacitor (c ext ) values and the operating temperature. in addition to this, the oscillator frequency will vary from unit to unit due to normal threshold voltage. furthermore, the difference in lead frame capacitance between package types will also affect the oscillation frequency or for low c ext values. the user also needs to take into account variation due to tolerance of external rc components used. 4.4 internal clock modes the PIC16F917/916/914/913 has two independent, internal oscillators that can be configured or selected as the system clock source. 1. the hfintosc (high-frequency internal oscillator) is factory calibrated and operates at 8 mhz. the frequency of the hfintosc can be user adjusted 12% via software using the osctune register (register 4-2). 2. the lfintosc (low-frequency internal oscillator) is uncalibrated and operates at approximately 31 khz. the system clock speed can be selected via software using the internal oscillator frequency select (ircf) bits. the system clock can be selected between external or internal clock sources via the system clock selection (scs) bit (see section 4.5 ?clock switching? ). 4.4.1 intosc and intoscio modes the intosc and intoscio modes configure the internal oscillators as the system clock source when the device is programmed using the oscillator selection (fosc) bits in the configuration word register (register 16-1). in intosc mode, the osc1 pin is available for general purpose i/o. the osc2/clko pin outputs the selected internal oscillator frequency divided by 4. the clko signal may be used to provide a clock for external circuitry, synchronization, calibration, test or other application requirements. in intoscio mode, the osc1 and osc2 pins are available for general purpose i/o. 4.4.2 hfintosc the high-frequency internal oscillator (hfintosc) is a factory calibrated 8 mhz internal clock source. the frequency of the hfintosc can be altered approximately 12% via software using the osctune register (register 4-2). the output of the hfintosc connects to a postscaler and multiplexer (see figure 4-1). one of seven frequencies can be selected via software using the ircf bits (see section 4.4.4 ?frequency select bits (ircf)? ). the hfintosc is enabled by selecting any frequency between 8 mhz and 125 khz (ircf 000 ) as the system clock source (scs = 1 ), or when two-speed start-up is enabled (ieso = 1 and ircf 000 ). the hf internal oscillator (hts) bit (osccon<2>) indicates whether the hfintosc is stable or not. osc2/clko c ext r ext PIC16F917/916/914/913 osc1 f osc /4 internal clock v dd v ss recommended values: 3 k r ext 100 k c ext > 20 pf i/o (osc2) c ext r ext PIC16F917/916/914/913 osc1 ra6 internal clock v dd v ss recommended values:3 k r ext 100 k c ext > 20 pf
PIC16F917/916/914/913 ds41250d-page 76 preliminary ? 2005 microchip technology inc. 4.4.2.1 osctune register the hfintosc is factory calibrated but can be adjusted in software by writing to the osctune register (register 4-2). the osctune register has a tuning range of 12%. the default value of the osctune register is ? 0 ?. the value is a 5-bit two?s complement number. due to process variation, the monotonicity and frequency step cannot be specified. when the osctune register is modified, the hfintosc frequency will begin shifting to the new frequency. the hfintosc clock will stabilize within 1 ms. code execution continues during this shift. there is no indication that the shift has occurred. osctune does not affect the lfintosc frequency. operation of features that depend on the lfintosc clock source frequency, such as the power-up timer (pwrt), watchdog timer (wdt), fail-safe clock monitor (fscm) and peripherals, are not affected by the change in frequency. register 4-2: osctune ? oscillator tuning resistor (address: 90h) u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? tun4 tun3 tun2 tun1 tun0 bit 7 bit 0 bit 7-5 unimplemented: read as ? 0 ? bit 4-0 tun<4:0>: frequency tuning bits 01111 = maximum frequency 01110 = ? ? ? 00001 = 00000 = center frequency. oscillator module is running at the calibrated frequency. 11111 = ? ? ? 10000 = minimum frequency legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. preliminary ds41250d-page 77 PIC16F917/916/914/913 4.4.3 lfintosc the low-frequency internal oscillator (lfintosc) is an uncalibrated (approximate) 31 khz internal clock source. the output of the lfintosc connects to a postscaler and multiplexer (see figure 4-1). 31 khz can be selected via software using the ircf bits (see section 4.4.4 ?frequency select bits (ircf)? ). the lfintosc is also the frequency for the power-up timer (pwrt), watchdog timer (wdt) and fail-safe clock monitor (fscm). the lfintosc is enabled by selecting 31 khz (ircf = 000 ) as the system clock source (scs = 1 ), or when any of the following are enabled: ? two-speed start-up (ieso = 1 and ircf = 000 ) ? power-up timer (pwrt) ? watchdog timer (wdt) ? fail-safe clock monitor (fscm) ? selected as lcd module clock source the lf internal oscillator (lts) bit (osccon<1>) indicates whether the lfintosc is stable or not. 4.4.4 frequency select bits (ircf) the output of the 8 mhz hfintosc and 31 khz lfintosc connect to a postscaler and multiplexer (see figure 4-1). the internal oscillator frequency select bits, ircf<2:0> (osccon<6:4>), select the frequency output of the internal oscillators. one of eight frequencies can be selected via software: ?8 mhz ? 4 mhz (default after reset) ?2 mhz ?1 mhz ? 500 khz ? 250 khz ? 125 khz ?31 khz 4.4.5 hf and lf intosc clock switch timing when switching between the lfintosc and the hfintosc, the new oscillator may already be shut down to save power. if this is the case, there is a 10 s delay after the ircf bits are modified before the frequency selection takes place. the lts/hts bits will reflect the current active status of the lfintosc and the hfintosc oscillators. the timing of a frequency selection is as follows: 1. ircf bits are modified. 2. if the new clock is shut down, a 10 s clock start-up delay is started. 3. clock switch circuitry waits for a falling edge of the current clock. 4. clko is held low and the clock switch circuitry waits for a rising edge in the new clock. 5. clko is now connected with the new clock. hts/lts bits are updated as required. 6. clock switch is complete. if the internal oscillator speed selected is between 8 mhz and 125 khz, there is no start-up delay before the new frequency is selected. this is because the old and the new frequencies are derived from the hfintosc via the postscaler and multiplexer. 4.5 clock switching the system clock source can be switched between external and internal clock sources via software using the system clock select (scs) bit. 4.5.1 system clock select (scs) bit the system clock select (scs) bit (osccon<0>) selects the system clock source that is used for the cpu and peripherals. ? when scs = 0 , the system clock source is determined by configuration of the fosc<2:0> bits in the configuration word register (config). ? when scs = 1 , the system clock source is chosen by the internal oscillator frequency selected by the ircf bits. after a reset, scs is always cleared. note: following any reset, the ircf bits are set to ? 110 ? and the frequency selection is set to 4 mhz. the user can modify the ircf bits to select a different frequency. note: any automatic clock switch, which may occur from two-speed start-up or fail-safe clock monitor, does not update the scs bit. the user can monitor the osts (osccon<3>) to determine the current system clock source.
PIC16F917/916/914/913 ds41250d-page 78 preliminary ? 2005 microchip technology inc. 4.5.2 oscillator start-up time-out status bit the oscillator start-up time-out status (osts) bit (osccon<3>) indicates whether the system clock is running from the external clock source, as defined by the fosc bits, or from the internal clock source. in particular, osts indicates that the oscillator start-up timer (ost) has timed out for lp, xt or hs modes. 4.6 two-speed clock start-up mode two-speed start-up mode provides additional power savings by minimizing the latency between external oscillator start-up and code execution. in applications that make heavy use of the sleep mode, two-speed start-up will remove the external oscillator start-up time from the time spent awake and can reduce the overall power consumption of the device. this mode allows the application to wake-up from sleep, perform a few instructions using the intosc as the clock source and go back to sleep without waiting for the primary oscillator to become stable. when the PIC16F917/916/914/913 is configured for lp, xt or hs modes, the oscillator start-up timer (ost) is enabled (see section 4.3.1 ?oscillator start-up timer (ost)? ). the ost timer will suspend program execution until 1024 oscillations are counted. two-speed start-up mode minimizes the delay in code execution by operating from the internal oscillator as the ost is counting. when the ost count reaches 1024 and the osts bit (osccon<3>) is set, program execution switches to the external oscillator. 4.6.1 two-speed start-up mode configuration two-speed start-up mode is configured by the following settings: ? ieso = 1 (config<10>) internal/external switchover bit. ?scs = 0 . ? fosc configured for lp, xt or hs mode. two-speed start-up mode is entered after: ? power-on reset (por) and, if enabled, after pwrt has expired, or ? wake-up from sleep. if the external clock oscillator is configured to be anything other than lp, xt or hs mode, then two-speed start-up is disabled. this is because the external clock oscillator does not require any stabilization time after por or an exit from sleep. 4.6.2 two-speed start-up sequence 1. wake-up from power-on reset or sleep. 2. instructions begin execution by the internal oscillator at the frequency set in the ircf bits (osccon<6:4>). 3. ost enabled to count 1024 clock cycles. 4. ost timed out, wait for falling edge of the internal oscillator. 5. osts is set. 6. system clock held low until the next falling edge of new clock (lp, xt or hs mode). 7. system clock is switched to external clock source. 4.6.3 checking external/internal clock status checking the state of the osts bit (osccon<3>) will confirm if the PIC16F917/916/914/913 is running from the external clock source as defined by the fosc bits in the configuration word (config) or the internal oscillator. note: executing a sleep instruction will abort the oscillator start-up time and will cause the osts bit (osccon<3>) to remain clear.
? 2005 microchip technology inc. preliminary ds41250d-page 79 PIC16F917/916/914/913 figure 4-7: two-speed start-up 4.7 fail-safe clock monitor the fail-safe clock monitor (fscm) is designed to allow the device to continue to operate in the event of an oscillator failure. the fscm can detect oscillator failure at any point after the device has exited a reset or sleep condition and the oscillator start-up timer (ost) has expired. figure 4-8: fscm block diagram the fscm function is enabled by setting the fcmen bit in the configuration word (config). it is applicable to all external clock options (lp, xt, hs, ec or rc modes). in the event of an external clock failure, the fscm will set the osfif bit (pir2<7>) and generate an oscillator fail interrupt if the osfie bit (pie2<7>) is set. the device will then switch the system clock to the internal oscillator. the system clock will continue to come from the internal oscillator unless the external clock recovers and the fail-safe condition is exited. the frequency of the internal oscillator will depend upon the value contained in the ircf bits (osccon<6:4>). upon entering the fail-safe condition, the osts bit (osccon<3>) is automatically cleared to reflect that the internal oscillator is active and the wdt is cleared. the scs bit (osccon<0>) is not updated. enabling fscm does not affect the lts bit. the fscm sample clock is generated by dividing the intosc clock by 64. this will allow enough time between fscm sample clocks for a system clock edge to occur. figure 4-8 shows the fscm block diagram. on the rising edge of the sample clock, a monitoring latch (cm = 0 ) will be cleared. on a falling edge of the primary system clock, the monitoring latch will be set (cm = 1 ). in the event that a falling edge of the sample clock occurs, and the monitoring latch is not set, a clock failure has been detected. the assigned internal oscillator is enabled when fscm is enabled as reflected by the ircf. q1 q2 q3 q4 q1 q2 q3 q4 q1 0 1 1022 1023 pc pc + 1 pc + 2 t ost t intosc osc1 osc2 program counter system clock primary lfintosc 64 oscillator clock clock fail detector clock failure detected note 1: two-speed start-up is automatically enabled when the fail-safe clock monitor mode is enabled. 2: primary clocks with a frequency ~488 hz will be considered failed by the fscm. a slow starting oscillator can cause an fscm interrupt.
PIC16F917/916/914/913 ds41250d-page 80 preliminary ? 2005 microchip technology inc. 4.7.1 fail-safe condition clearing the fail-safe condition is cleared after a reset, the execution of a sleep instruction, or a modification of the scs bit. while in fail-safe condition, the pic16f91x uses the internal oscillator as the system without exiting the fail-safe condition. the fail-safe condition must be cleared before the osfif flag can be cleared. figure 4-9: fscm timing diagram 4.7.2 reset or wake-up from sleep the fscm is designed to detect oscillator failure at any point after the device has exited a reset or sleep condition and the oscillator start-up timer (ost) has expired. if the external clock is ec or rc mode, monitoring will begin immediately following these events. for lp, xt or hs mode the external oscillator may require a start-up time considerably longer than the fscm sample clock time, a false clock failure may be detected (see figure 4-9). to prevent this, the internal oscillator is automatically configured as the system clock and functions until the external clock is stable (the ost has timed out). this is identical to two-speed start-up mode. once the external oscillator is stable, the lfintosc returns to its role as the fscm source. table 4-2: summary of registers associated with clock sources oscfif cm output system clock output sample clock failure detected oscillator failure note: the system clock is normally at a much higher frequency than the sample clock. the relative frequencies in this example have been chosen for clarity. (q ) cm test cm test cm test note: due to the wide range of oscillator start-up times, the fail-safe circuit is not active during oscillator start-up (i.e., after exiting reset or sleep). after an appropriate amount of time, the user should check the osts bit (osccon<3>) to verify the oscillator start-up and system clock switchover has successfully completed. addr name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 8fh osccon ? ircf2 ircf1 ircf0 osts (2) hts lts scs -110 q000 -110 x000 90h osctune ? ? ? tun4 tun3 tun2 tun1 tun0 ---0 0000 ---u uuuu 2007h (1) config cpd cp mclre pwrte wdte fosc2 fosc1 fosc0 ? ? legend: x = unknown, u = unchanged, - = unimplemented locations read as ? 0 ?. shaded cells are not used by oscillators. note 1: see register 16-1 for operation of all configuration word bits. 2: see register 4-1 for details.
? 2005 microchip technology inc. preliminary ds41250d-page 81 PIC16F917/916/914/913 5.0 timer0 module the timer0 module timer/counter has the following features: ? 8-bit timer/counter ? readable and writable ? 8-bit software programmable prescaler ? internal or external clock select ? interrupt on overflow from ffh to 00h ? edge select for external clock figure 5-1 is a block diagram of the timer0 module and the prescaler shared with the wdt. 5.1 timer0 operation timer mode is selected by clearing the t0cs bit (option_reg<5>). in timer mode, the timer0 module will increment every instruction cycle (without prescaler). if tmr0 is written, the increment is inhibited for the following two instruction cycles. the user can work around this by writing an adjusted value to the tmr0 register. counter mode is selected by setting the t0cs bit (option_reg<5>). in this mode, the timer0 module will increment either on every rising or falling edge of pin ra4/c1out/t0cki/seg4. the incrementing edge is determined by the source edge (t0se) control bit (option_reg<4>). clearing the t0se bit selects the rising edge. 5.2 timer0 interrupt a timer0 interrupt is generated when the tmr0 register timer/counter overflows from ffh to 00h. this overflow sets the t0if bit (intcon<2>). the interrupt can be masked by clearing the t0ie bit (intcon<5>). the t0if bit must be cleared in software by the timer0 module interrupt service routine before re-enabling this interrupt. the timer0 interrupt cannot wake the processor from sleep, since the timer is shut off during sleep. figure 5-1: block diagram of th e timer0/wdt prescaler note: additional information on the timer0 module is available in the ? picmicro ? mid-range mcu family reference manual ? (ds33023). note: counter mode has specific external clock requirements. additional information on these requirements is available in the ? picmicro ? mid-range mcu family reference manual ? (ds33023). t0cki t0se pin clko tmr0 watchdog timer wdt time-out ps<2:0> wdte data bus set flag bit t0if on overflow t0cs note: t0se, t0cs, psa and ps<2:0> are bits in the option register; wdtps<3:0> are bits in the wdtcon register. 0 1 0 1 0 1 sync 2 cycles 8 8 8-bit prescaler 0 1 (= f osc /4) psa psa psa 16-bit prescaler 16 wdtps<3:0> 31 khz intosc swdten
PIC16F917/916/914/913 ds41250d-page 82 preliminary ? 2005 microchip technology inc. 5.3 using timer0 with an external clock when no prescaler is used, the external clock input is the same as the prescaler output. the synchronization of t0cki, with the internal phase clocks, is accomplished by sampling the prescaler output on the q2 and q4 cycles of the internal phase clocks. therefore, it is necessary for t0cki to be high for at least 2 t osc (and a small rc delay of 20 ns) and low for at least 2 t osc (and a small rc delay of 20 ns). refer to the electrical specification of the desired device. register 5-1: option_reg ? option register (address: 81h or 181h) r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg t0cs t0se psa ps2 ps1 ps0 bit 7 bit 0 bit 7 rbpu : portb pull-up enable bit 1 = portb pull-ups are disabled 0 = portb pull-ups are enabled by individual port latch values in wpua register bit 6 intedg: interrupt edge select bit 1 = interrupt on rising edge of rb0/int/seg0 pin 0 = interrupt on falling edge of rb0/int/seg0 pin bit 5 t0cs: tmr0 clock source select bit 1 = transition on ra4/c1out/t0cki/seg4 pin 0 = internal instruction cycle clock (clko) bit 4 t0se: tmr0 source edge select bit 1 = increment on high-to-low transition on ra4/c1out/t0cki/seg4 pin 0 = increment on low-to-high transition on ra4/c1out/t0cki/seg4 pin bit 3 psa: prescaler assignment bit 1 = prescaler is assigned to the wdt 0 = prescaler is assigned to the timer0 module bit 2-0 ps<2:0>: prescaler rate select bits note 1: a dedicated 16-bit wdt postscaler is available for the PIC16F917/916/914/913. see section 16.6 ?watchdog timer (wdt)? for more information. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown 000 001 010 011 100 101 110 111 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 1 : 256 1 : 1 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 bit value tmr0 rate wdt rate (1)
? 2005 microchip technology inc. preliminary ds41250d-page 83 PIC16F917/916/914/913 5.4 prescaler an 8-bit counter is available as a prescaler for the timer0 module, or as a postscaler for the watchdog timer. for simplicity, this counter will be referred to as ?prescaler? throughout this data sheet. the prescaler assignment is controlled in software by the control bit psa (option_reg<3>). clearing the psa bit will assign the prescaler to timer0. prescale values are selectable via the ps<2:0> bits (option_reg<2:0>). the prescaler is not readable or writable. when assigned to the timer0 module, all instructions writing to the tmr0 register (e.g., clrf 1, movwf 1, bsf 1, x....etc. ) will clear the prescaler. when assigned to wdt, a clrwdt instruction will clear the prescaler along with the watchdog timer. 5.4.1 switching prescaler assignment the prescaler assignment is fully under software control (i.e., it can be changed ?on-the-fly? during program execution). to avoid an unintended device reset, the following instruction sequence (example 5-1 and example 5-2) must be executed when changing the prescaler assignment from timer0 to wdt. example 5-1: changing prescaler (timer0 wdt) to change prescaler from the wdt to the tmr0 module, use the sequence shown in example 5-2. this precaution must be taken even if the wdt is disabled. example 5-2: changing prescaler (wdt timer0) table 5-1: registers associated with timer0 bcf status,rp0 ;bank 0 clrwdt ;clear wdt clrf tmr0 ;clear tmr0 and ; prescaler bsf status,rp0 ;bank 1 movlw b?00101111? ;required if desired movwf option_reg ; ps2:ps0 is clrwdt ; 000 or 001 ; movlw b?00101xxx? ;set postscaler to movwf option_reg ; desired wdt rate bcf status,rp0 ;bank 0 clrwdt ;clear wdt and ; prescaler bsf status,rp0 ;bank 1 movlw b?xxxx0xxx? ;select tmr0, ; prescale, and ; clock source movwf option_reg ; bcf status,rp0 ;bank 0 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 01h tmr0 timer0 module register xxxx xxxx uuuu uuuu 0bh/10bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 81h option_reg r bp u intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 legend: - = unimplemented locations, read as ? 0 ?, u = unchanged, x = unknown. shaded cells are not used by the timer0 module.
PIC16F917/916/914/913 ds41250d-page 84 preliminary ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. preliminary ds41250d-page 85 PIC16F917/916/914/913 6.0 timer1 module with gate control the PIC16F917/916/914/913 has a 16-bit timer. figure 6-1 shows the basic block diagram of the timer1 module. timer1 has the following features: ? 16-bit timer/counter (tmr1h:tmr1l) ? readable and writable ? internal or external clock selection ? synchronous or asynchronous operation ? interrupt-on-overflow from ffffh to 0000h ? wake-up upon overflow (asynchronous mode) ? optional external enable input: - selectable gate source: t1g or c2 output (t1gss) - selectable gate polarity (t1ginv) ? optional lp oscillator the timer1 control register (t1con), shown in register 6-1, is used to enable/disable timer1 and select the various features of the timer1 module. figure 6-1: timer1 on the PIC16F917/916/914/913 block diagram note: additional information on timer modules is available in the ? picmicro ? mid-range mcu family reference manual? (ds33023). tmr1h tmr1l lp osc t1sync t1ckps<1:0> sleep input f osc /4 internal clock prescaler 1, 2, 4, 8 synchronize det 1 0 0 1 synchronized clock input 2 osc1/t1osi osc2/t1oso set flag bit tmr1if on overflow tmr1 (1) tmr1on t1ge tmr1on t1ge f osc = 000 t1oscen f osc = x00 1 0 c2out t1gss t1ginv to c2 comparator module tmr1 clock note 1: timer1 increments on the rising edge. 2: st buffer is low-power type when using lp oscillator or high-speed type when using t1cki. rc4/t1g / 1 0 rc5/t1cki/ t1cs (2) clear on special event trigger sdo/seg11 ccp1/seg10
PIC16F917/916/914/913 ds41250d-page 86 preliminary ? 2005 microchip technology inc. 6.1 timer1 modes of operation timer1 can operate in one of three modes: ? 16-bit timer with prescaler ? 16-bit synchronous counter ? 16-bit asynchronous counter in timer mode, timer1 is incremented on every instruction cycle. in counter mode, timer1 is incremented on the rising edge of the external clock input t1cki. in addition, the counter mode clock can be synchronized to the microcontroller system clock or run asynchronously. in the timer1 module, the module clock can be gated by the timer1 gate, which can be selected as either the t1g pin or comparator 2 output. if an external clock oscillator is needed (and the microcontroller is using the intosc without clko), timer1 can use the lp oscillator as a clock source. 6.2 timer1 interrupt the timer1 register pair (tmr1h:tmr1l) increments to ffffh and rolls over to 0000h. when timer1 rolls over, the timer1 interrupt flag bit (pir1<0>) is set. to enable the interrupt on rollover, you must set these bits: ? timer1 interrupt enable bit (pie1<0>) ? peie bit (intcon<6>) ? gie bit (intcon<7>) the interrupt is cleared by clearing the tmr1if bit in the interrupt service routine. 6.3 timer1 prescaler timer1 has four prescaler options allowing 1, 2, 4 or 8 divisions of the clock input. the t1ckps bits (t1con<5:4>) control the prescale counter. the prescale counter is not directly readable or writable; however, the prescaler counter is cleared upon a write to tmr1h or tmr1l. 6.4 timer1 gate timer1 gate source is software configurable to be the t1g pin or the output of comparator 2. this allows the device to directly time external events using t1g or analog events using comparator 2. see cmcon1 (register 8-2) for selecting the timer1 gate source. this feature can simplify the software for a delta-sigma a/d converter and many other applications. for more information on delta-sigma a/d converters, see the microchip web site (www.microchip.com). timer1 gate can be inverted using the t1ginv bit (t1con<7>), whether it originates from the t1g pin or comparator 2 output. this configures timer1 to measure either the active-high or active-low time between events. figure 6-2: timer1 incrementing edge note: in counter mode, a falling edge must be registered by the counter prior to the first incrementing rising edge. note: the tmr1h:ttmr1l register pair and the tmr1if bit should be cleared before enabling interrupts. note: t1ge bit (t1con<6>) must be set to use either t1g or c2out as the timer1 gate source. see register 8-2 for more information on selecting the timer1 gate source. t1cki = 1 when tmr1 enabled t1cki = 0 when tmr1 enabled note 1: arrows indicate counter increments. 2: in counter mode, a falling edge must be registered by the counter prior to the first incrementing rising edge of the clock.
? 2005 microchip technology inc. preliminary ds41250d-page 87 PIC16F917/916/914/913 register 6-1: t1con ? timer1 control regi ster (address: 10h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 t1ginv t1ge t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on bit 7 bit 0 bit 7 t1ginv: timer1 gate invert bit (1) 1 = timer1 gate is inverted 0 = timer1 gate is not inverted bit 6 t1ge: timer1 gate enable bit (2) if tmr1on = 0 : this bit is ignored. if tmr1on = 1 : 1 = timer1 gate is enabled 0 = timer1 gate is disabled bit 5-4 t1ckps<1:0>: timer1 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 t1oscen: lp oscillator enable control bit if intosc without clko o scillator is active: 1 = lp oscillator is enabled for timer1 clock 0 = lp oscillator is off else: this bit is ignored. bit 2 t1sync : timer1 external clock input synchronization control bit tmr1cs = 1 : 1 = do not synchronize external clock input 0 = synchronize external clock input tmr1cs = 0 : this bit is ignored. timer1 uses the internal clock. bit 1 tmr1cs: timer1 clock source select bit 1 = external clock from rc5/t1cki/ccp1/seg10 pin or t1osc (on the rising edge) 0 = internal clock (f osc /4) bit 0 tmr1on: timer1 on bit 1 = enables timer1 0 = stops timer1 note 1: t1ginv bit inverts the timer1 gate logic, regardless of source. 2: t1ge bit must be set to use either t1g pin or c2out, as selected by the t1gss bit (cmcon1<1>), as a timer1 gate source. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
PIC16F917/916/914/913 ds41250d-page 88 preliminary ? 2005 microchip technology inc. 6.5 timer1 operation in asynchronous counter mode if control bit t1sync (t1con<2>) is set, the external clock input is not synchronized. the timer continues to increment asynchronous to the internal phase clocks. the timer will continue to run during sleep and can generate an interrupt-on-overflow, which will wake-up the processor. however, special precautions in software are needed to read/write the timer (see section 6.5.1 ?reading and writing timer1 in asynchronous counter mode? ). 6.5.1 reading and writing timer1 in asynchronous counter mode reading tmr1h or tmr1l, while the timer is running from an external asynchronous clock, will ensure a valid read (taken care of in hardware). however, the user should keep in mind that reading the 16-bit timer in two 8-bit values itself, poses certain problems, since the timer may overflow between the reads. for writes, it is recommended that the user simply stop the timer and write the desired values. a write contention may occur by writing to the timer registers, while the register is incrementing. this may produce an unpredictable value in the timer register. reading the 16-bit value requires some care. examples in the ? picmicro ? mid-range mcu family reference manual? (ds33023) show how to read and write timer1 when it is running in asynchronous mode. 6.6 timer1 oscillator to minimize the multiplexing of peripherals on the i/o ports, the dedicated tmr1 oscillator, which is normally used for tmr1 real-time clock applications, is eliminated. instead, the tmr1 module can enable the lp oscillator. if the microcontroller is programmed to run from intosc with no clko or lp oscillator: 1. setting the t1oscen and tmr1cs bits to ? 1 ? will enable the lp oscillator to clock tmr1 while the microcontroller is clocked from either the intosc or lp oscillator. note that the t1osc and lp oscillators share the same circuitry. therefore, when lp oscillator is selected and t1osc is enabled, both the microcontroller and the timer1 module share the same clock source. 2. sleep mode does not shut off the lp oscillator operation (i.e., if the intosc oscillator runs the microcontroller, and t1oscen = 1 (tmr1 is running from the lp oscillator), then the lp oscillator will continue to run during sleep mode. in all oscillator modes except for intosc with no clkout and lp, the t1osc enable option is unavail- able and is ignored. 6.7 resetting timer1 using a ccp trigger output if the ccp1 or ccp2 module is configured in compare mode to generate a ?special event trigger? (ccp1m<3:0> = 1011 ), this signal will reset timer1. timer1 must be configured for either timer or synchro- nized counter mode to take advantage of this feature. if timer1 is running in asynchronous counter mode, this reset operation may not work. in the event that a write to timer1 coincides with a special event trigger from ccp1 or ccp2, the write will take precedence. in this mode of operation, the ccprxh:ccprxl register pair effectively becomes the period register for timer1. note: the ansel (91h) and cmcon0 (9ch) registers must be initialized to configure an analog channel as a digital input. pins configured as analog inputs will read ? 0 ?. note: when intosc without clko oscillator is selected and t1oscen = 1 , the lp oscillator will run continuously independent of the tmr1on bit. note: the special event triggers from the ccp1 and ccp2 modules will not set interrupt flag bit, tmr1if (pir1<0>).
? 2005 microchip technology inc. preliminary ds41250d-page 89 PIC16F917/916/914/913 6.8 resetting of timer1 register pair (tmr1h, tmr1l) tmr1h and tmr1l registers are not reset to 00h on a por, or any other reset, except by the ccp1 and ccp2 special event triggers. t1con register is reset to 00h on a power-on reset, or a brown-out reset, which shuts off the timer and leaves a 1:1 prescale. in all other resets, the register is unaffected. 6.9 timer1 operation during sleep timer1 can only operate during sleep when setup in asynchronous counter mode. in this mode, an external crystal or clock source can be used to increment the counter. to set up the timer to wake the device: ? timer1 must be on (t1con<0>) ? tmr1ie bit (pie1<0>) must be set ? peie bit (intcon<6>) must be set the device will wake-up on an overflow. if the gie bit (intcon<7>) is set, the device will wake-up and jump to the interrupt service routine (0004h) on an overflow. if the gie bit is clear, execution will continue with the next instruction. table 6-1: registers associated with timer1 addr name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 0bh/ 8bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 10h t1con t1ginv t1ge t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0000 0000 uuuu uuuu 1ah cmcon1 ? ? ? ? ? ?t1gss c2sync ---- --10 ---- --10 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by the timer1 module.
PIC16F917/916/914/913 ds41250d-page 90 preliminary ? 2005 microchip technology inc. 7.0 timer2 module the timer2 module timer has the following features: ? 8-bit timer (tmr2 register) ? 8-bit period register (pr2) ? readable and writable (both registers) ? software programmable prescaler (1:1, 1:4, 1:16) ? software programmable postscaler (1:1 to 1:16) ? interrupt on tmr2 match with pr2 timer2 has a control register shown in register 7-1. tmr2 can be shut-off by clearing control bit tmr2on (t2con<2>) to minimize power consumption. figure 7-1 is a simplified block diagram of the timer2 module. the prescaler and postscaler selection of timer2 are controlled by this register. 7.1 timer2 operation timer2 can be used as the pwm time base for the pwm mode of the ccp module. the tmr2 register is readable and writable, and is cleared on any device reset. the input clock (f osc /4) has a prescale option of 1:1, 1:4 or 1:16, selected by control bits t2ckpsx (t2con<1:0>). the match output of tmr2 goes through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive) to generate a tmr2 interrupt (latched in flag bit tmr2if, (pir1<1>)). the prescaler and postscaler counters are cleared when any of the following occurs: ? a write to the tmr2 register ? a write to the t2con register ? any device reset (power-on reset, mclr reset, watchdog timer reset, or brown-out reset) tmr2 is not cleared when t2con is written. register 7-1: t2con ? timer2 control register (address: 12 h ) u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6-3 toutps<3:0>: timer2 output postscale select bits 0000 =1:1 postscale 0001 =1:2 postscale ? ? ? 1111 =1:16 postscale bit 2 tmr2on: timer2 on bit 1 = timer2 is on 0 = timer2 is off bit 1-0 t2ckps<1:0>: timer2 clock prescale select bits 00 =prescaler is 1 01 =prescaler is 4 1x =prescaler is 16 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. preliminary ds41250d-page 91 PIC16F917/916/914/913 7.2 timer2 interrupt the timer2 module has an 8-bit period register, pr2. timer2 increments from 00h until it matches pr2 and then resets to 00h on the next increment cycle. pr2 is a readable and writable register. the pr2 register is initialized to ffh upon reset. 7.3 timer2 output the output of tmr2 (before the postscaler) is fed to the ssp module, which optionally uses it to generate the shift clock. figure 7-1: timer2 block diagram table 7-1: registers associated with timer2 addr name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 0bh/ 8bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 11h tmr2 holding register fo r the 8-bit tmr2 register 0000 0000 0000 0000 12h t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 92h pr2 timer2 period register 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by the timer2 module. comparator tmr2 sets flag tmr2 output (1) reset postscaler prescaler pr2 2 f osc /4 1:1 to 1:16 1:1, 1:4, 1:16 eq 4 bit tmr2if toutps<3:0> t2ckps<1:0> note 1: tmr2 register output can be software selected by the ssp module as a baud clock.
PIC16F917/916/914/913 ds41250d-page 92 preliminary ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. preliminary ds41250d-page 93 PIC16F917/916/914/913 8.0 comparator module the comparator module contains two analog comparators. the inputs to the comparators are multiplexed with i/o port pins ra<3:0>, while the outputs are multiplexed to pins ra<5:4>. an on-chip comparator voltage reference (cv ref ) can also be applied to the inputs of the comparators. the cmcon0 register (register 8-1) controls the comparator input and output multiplexers. a block diagram of the various comparator configurations is shown in figure 8-3. register 8-1: cmcon0 ? comparator co nfiguration register (address: 9ch) r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 c2out c1out c2inv c1inv cis cm2 cm1 cm0 bit 7 bit 0 bit 7 c2out: comparator 2 output bit when c2inv = 0 : 1 =c2 v in + > c2 v in - 0 =c2 v in + < c2 v in - when c2inv = 1 : 0 =c2 v in + > c2 v in - 1 =c2 v in + < c2 v in - bit 6 c1out: comparator 1 output bit when c1inv = 0 : 1 =c1 v in + > c1 v in - 0 =c1 v in + < c1 v in - when c1inv = 1 : 0 =c1 v in + > c1 v in - 1 =c1 v in + < c1 v in - bit 5 c2inv: comparator 2 output inversion bit 1 = c2 output inverted 0 = c2 output not inverted bit 4 c1inv: comparator 1 output inversion bit 1 = c1 output inverted 0 = c1 output not inverted bit 3 cis: comparator input switch bit when cm<2:0> = 010 : 1 =c1 v in - connects to ra3/an3/c1+/v ref +/seg15 c2 v in - connects to ra2/an2/c2+/v ref -/com2 0 =c1 v in - connects to ra0/an0/c1-/seg12 c2 v in - connects to ra1/an1/c2-/seg7 when cm<2:0> = 001 : 1 =c1 v in - connects to ra3/an3/c1+/v ref +/seg15 0 =c1 v in - connects to ra0/an0/c1-/seg12 when cm<2:0> = 101 : 1 =c2 v in + connects to internal 0.6v reference 0 =c2 v in + connects to ra2/an2/c2+/v ref -/com2 bit 2-0 cm<2:0>: comparator mode bits (1) see figure 8-3 for comparator modes and cm<2:0> bit settings. note 1: setting a pin to an analog input automatically disables the digital input circuitry, weak pull-ups, and interrupt-on-change if available. the corresponding tris bit must be set to input mode in order to allow external control of the voltage on the pin. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
PIC16F917/916/914/913 ds41250d-page 94 preliminary ? 2005 microchip technology inc. 8.1 comparator operation a single comparator is shown in figure 8-1 along with the relationship between the analog input levels and the digital output. when the analog input at v in + is less than the analog input v in -, the output of the comparator is a digital low level. when the analog input at v in + is greater than the analog input v in -, the output of the comparator is a digital high level. the shaded areas of the output of the comparator in figure 8-1 represent the uncertainty due to input offsets and response time. the polarity of the comparator output can be inverted by setting the cxinv bits (cmcon0<5:4>). clearing cxinv results in a non-inverted output. a complete table showing the output state versus input conditions and the polarity bit is shown in table 8-1. table 8-1: output state vs. input conditions figure 8-1: single comparator 8.2 analog input connection considerations a simplified circuit for an analog input is shown in figure 8-2. since the analog pins are connected to a digital output, they have reverse biased diodes to v dd and v ss . the analog input, therefore, must be between v ss and v dd . if the input voltage deviates from this range by more than 0.6v in either direction, one of the diodes is forward biased and a latch-up may occur. a maximum source impedance of 10 k is recommended for the analog sources. any external component connected to an analog input pin, such as a capacitor or a zener diode, should have very little leakage. figure 8-2: analog input model note: to use cin+ and cin- pins as analog inputs, the appropriate bits must be programmed in the cmcon0 (9ch) register. input conditions cinv cxout v in - > v in + 00 v in - < v in + 01 v in - > v in + 11 v in - < v in + 10 v in? v in+ o utput ? + v in + v in - output output v in + v in - va rs < 10k a in c pin 5 pf v dd v t = 0.6v v t = 0.6v r ic leakage 500 na vss legend: c pin = input capacitance v t = threshold voltage i leakage = leakage current at the pin due to various junctions r ic = interconnect resistance r s = source impedance va = analog voltage
? 2005 microchip technology inc. preliminary ds41250d-page 95 PIC16F917/916/914/913 8.3 comparator configuration there are eight modes of operation for the comparators. the cmcon0 register is used to select these modes. figure 8-3 shows the eight possible modes. if the comparator mode is changed, the comparator output level may not be valid for the specified mode change delay shown in section 19.0 ?electrical specifications? . figure 8-3: comparator i/o operating modes note: comparator interrupts should be disabled during a comparator mode change. otherwise, a false interrupt may occur. c1 ra0/an0/ v in - v in + ra3/an3/ off (read as ? 0 ?) comparators reset (por default value) a a cm<2:0> = 000 c2 ra1/an1/ v in - v in + ra2/an2/ off (read as ? 0 ?) a a c1 v in - v in + c1out two independent comparators a a cm<2:0> = 100 c2 v in - v in + c2out a a c1 v in - v in + c1out two common reference comparators a d cm<2:0> = 011 c2 v in - v in + c2out a a c1 v in - v in + off (read as ? 0 ?) one independent comparator with reference option d d cm<2:0> = 101 c2 v in - v in + c2out c1 v in - v in + off (r ead as ? 0 ?) comparators off d d cm<2:0> = 111 c2 v in - v in + off (r ead as ? 0 ?) d d c1 v in - v in + c1out four inputs multiplexed to two comparators a a cm<2:0> = 010 c2 v in - v in + c2out a a from cv ref module cis = 0 cis = 1 cis = 0 cis = 1 c1 v in - v in + c1out two common reference comparators with outputs a cm<2:0> = 110 c2 v in - v in + c2out a a c1 v in - v in + c1out three inputs multiplexed to two comparators a a cm<2:0> = 001 c2 v in - v in + c2out a a cis = 0 cis = 1 ra4 ra5 c1-/seg12 c1+/v ref +/seg15 ra0/an0/ c1-/seg12 ra3/an3/ c1+/v ref +/seg15 c2-/seg7 c2+/v ref -/com2 ra1/an1/ c2-/seg7 ra2/an2/ c2+/v ref -/com2 ra0/an0/ c1-/seg12 ra3/an3/ c1+/v ref +/seg15 ra1/an1/ c2-/seg7 ra2/an2/ c2+/v ref -/com2 ra0/an0/ c1-/seg12 ra3/an3/ c1+/v ref +/seg15 ra1/an1/ c2-/seg7 ra2/an2/ c2+/v ref -/com2 ra0/an0/ c1-/seg12 ra1/an1/ c2-/seg7 ra2/an2/ c2+/v ref -/com2 ra0/an0/ c1-/seg12 ra3/an3/ c1+/v ref +/seg15 ra1/an1/ c2-/seg7 ra2/an2/ c2+/v ref -/com2 ra2/an2/ c2+/v ref -/com2 ra1/an1/ c2-/seg7 ra3/an3/ c1+/v ref +/seg15 ra0/an0/ c1-/seg12 a a a cis = 0 cis = 1 ra0/an0/ c1-/seg12 ra1/an1/ c2-/seg7 ra2/an2/ c2+/v ref -/ com2 ra5 ra3/an3/ c1+/v ref +/ seg15 internal 0.6v reference legend: a = analog input, port reads zeros always. d = digital input. cis (cmcon0<3>) is the computer input switch.
PIC16F917/916/914/913 ds41250d-page 96 preliminary ? 2005 microchip technology inc. figure 8-4: comparator c1 output block diagram figure 8-5: comparator c2 output block diagram d q en to c 1 o u t p i n rd cmcon set c1if bit multiplex d q en cl port pins nreset to data bus c1inv rd cmcon c2sync d q en to c 2 o u t p in rd cmcon set c2if bit multiplex d q en cl port pins rd cmcon reset to data bus c2inv d q en tmr1 clock source (1) 0 1 to t m r 1 note 1: comparator 2 output is latched on falling edge of t1 clock source.
? 2005 microchip technology inc. preliminary ds41250d-page 97 PIC16F917/916/914/913 register 8-2: cmcon1 ? comparator co nfiguration register (address: 97h) 8.4 comparator outputs the comparator outputs are read through the cmcon0 register. these bits are read-only. the comparator outputs may also be directly output to the ra4 and ra5 i/o pins. when enabled, multiplexers in the output path of the ra4 and ra5 pins will switch and the output of each pin will be the unsynchronized output of the comparator. the uncertainty of each of the comparators is related to the input offset voltage and the response time given in the specifications. figure 8-4 and figure 8-5 show the output block diagram for comparator 1 and 2. the tris bits will still function as an output enable/disable for the ra4 and ra5 pins while in this mode. the polarity of the comparator outputs can be changed using the c1inv and c2inv bits (cmcon0<5:4>). timer1 gate source can be configured to use the t1g pin or comparator 2 output as selected by the t1gss bit (cmcon1<1>). this feature can be used to time the duration or interval of analog events. the output of comparator 2 can also be synchronized with timer1 by setting the c2sync bit (cmcon1<0>). when enabled, the output of comparator 2 is latched on the falling edge of timer1 clock source. if a prescaler is used with timer1, comparator 2 is latched after the prescaler. to prevent a race condition, the comparator 2 output is latched on the falling edge of the timer1 clock source and timer1 increments on the rising edge of its clock source. see (figure 8-5), comparator 2 block diagram and (figure 6-1), timer1 block diagram for more information. it is recommended to synchronize comparator 2 with timer1 by setting the c2sync bit when comparator 2 is used as the timer1 gate source. this ensures timer1 does not miss an increment if comparator 2 changes during an increment. 8.5 comparator interrupts the comparator interrupt flags are set whenever there is a change in the output value of its respective comparator. software will need to maintain information about the status of the output bits, as read from cmcon0<7:6>, to determine the actual change that has occurred. the cxif bits, pir2<6:5>, are the comparator interrupt flags. this bit must be reset in software by clearing it to ? 0 ?. since it is also possible to write a ? 1 ? to this register, a simulated interrupt may be initiated. the cxie bits (pie2<6:5>) and the peie bit (intcon<6>) must be set to enable the interrupts. in addition, the gie bit must also be set. if any of these bits are cleared, the interrupt is not enabled, though the cxif bits will still be set if an interrupt condition occurs. the user, in the interrupt service routine, can clear the interrupt in the following manner: a) any read or write of cmcon0. this will end the mismatch condition. b) clear flag bit cxif a mismatch condition will continue to set flag bit cxif. reading cmcon0 will end the mismatch condition and allow flag bits cxif to be cleared. u-0 u-0 u-0 u-0 u-0 u-0 r/w-1 r/w-0 ? ? ? ? ? ? t1gss c2sync bit 7 bit 0 bit 7-2: unimplemented : read as ? 0 ? bit 1 t1gss: timer1 gate source select bit 1 = timer1 gate source is t1g pin (rc4 must be configured as digital input) 0 = timer1 gate source is comparator 2 output bit 0 c2sync: comparator 2 synchronize bit 1 = c2 output synchronized with falling edge of timer1 clock 0 = c2 output not synchronized with timer1 clock legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown note: if a change in the cmcon0 register (cxout) should occur when a read operation is being executed (start of the q2 cycle), then the cxif (pir2<6:5>) interrupt flag may not get set.
PIC16F917/916/914/913 ds41250d-page 98 preliminary ? 2005 microchip technology inc. 8.6 comparator reference the comparator module also allows the selection of an internally generated voltage reference for one of the comparator inputs. the vrcon register, register 8-3, controls the voltage reference module shown in figure 8-6. 8.6.1 configuring the voltage reference the voltage reference can output 32 distinct voltage levels; 16 in a high range and 16 in a low range. the following equation determines the output voltages: equation 8-1: 8.6.2 voltage reference accuracy/error the full range of v ss to v dd cannot be realized due to the construction of the module. the transistors on the top and bottom of the resistor ladder network (figure 8-6) keep cv ref from approaching v ss or v dd . the exception is when the module is disabled by clearing the vren bit (vrcon<7>). when disabled, the reference voltage is v ss when vr<3:0> = 0000 . this allows the comparators to detect a zero-crossing and not consume cv ref module current. the voltage reference is v dd derived and therefore, the cv ref output changes with fluctuations in v dd . the tested absolute accuracy of the comparator voltage reference can be found in section 19.0 ?electrical specifications? . figure 8-6: comparator voltage reference block diagram vrr = 1 (low range): cv ref = (vr3:vr0/24) x v dd vrr = 0 (high range): cv ref = (v dd /4) + (vr3:vr0 x v dd /32) vrr 8r vr<3:0> 16-1 analog 8rrr rr cv ref to 16 stages comparator input vren v dd mux v ren vr <3:0> = ? 0000 ? vrr
? 2005 microchip technology inc. preliminary ds41250d-page 99 PIC16F917/916/914/913 8.7 comparator response time response time is the minimum time, after selecting a new reference voltage or input source, before the comparator output is ensured to have a valid level. if the internal reference is changed, the maximum delay of the internal voltage reference must be considered when using the comparator outputs. otherwise, the maximum delay of the comparators should be used (table 19-10). 8.8 operation during sleep the comparators and voltage reference, if enabled before entering sleep mode, remain active during sleep. this results in higher sleep currents than shown in the power-down specifications. the additional current consumed by the comparator and the voltage reference is shown separately in the specifications. to minimize power consumption while in sleep mode, turn off the comparator, cm<2:0> = 111 , and voltage reference, vrcon<7> = 0 . while the comparator is enabled during sleep, an interrupt will wake-up the device. if the gie bit (intcon<7>) is set, the device will jump to the inter- rupt vector (0004h), and if clear, continues execution with the next instruction. if the device wakes up from sleep, the contents of the cmcon0, cmcon1 and vrcon registers are not affected. 8.9 effects of a reset a device reset forces the cmcon0, cmcon1 and vrcon registers to their reset states. this forces the comparator module to be in the comparator reset mode, cm<2:0> = 000 and the voltage reference to its off state. thus, all potential inputs are analog inputs with the comparator and voltage reference disabled to consume the smallest current possible.
PIC16F917/916/914/913 ds41250d-page 100 preliminary ? 2005 microchip technology inc. register 8-3: vrcon ? voltage reference control register (address: 9dh) table 8-2: registers associated with comparator module r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 vren ?vrr ? vr3 vr2 vr1 vr0 bit 7 bit 0 bit 7 vren: cv ref enable bit 1 = cv ref circuit powered on 0 = cv ref circuit powered down, no i dd drain and cv ref = v ss . bit 6 unimplemented: read as ? 0 ? bit 5 vrr: cv ref range selection bit 1 = low range 0 = high range bit 4 unimplemented: read as ? 0 ? bit 3-0 vr<3:0>: cv ref value selection 0 vr<3:0> 15 when vrr = 1 : cv ref = (vr<3:0>/24) * v dd when vrr = 0 : cv ref = v dd /4 + (vr<3:0>/32) * v dd legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 0bh/8bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0dh pir2 osfif c2if c1if lcdif ? lvdif ? ccp2if 0000 -0-0 0000 -0-0 9ch cmcon0 c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0000 0000 0000 97h cmcon1 ? ? ? ? ? ? t1gss c2sync ---- --10 ---- --10 85h trisa trisa7 trisa6 trisa5 trisa4 tri sa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 8dh pie2 osfie c2ie c1ie lcdie ?lvdie ? ccp2ie 0000 -0-0 0000 -0-0 9dh vrcon vren ?vrr ? vr3 vr2 vr1 vr0 0-0- 0000 0-0- 0000 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by the comparator or comparator voltage reference module.
? 2005 microchip technology inc. preliminary ds41250d-page 101 PIC16F917/916/914/913 9.0 liquid crystal display (lcd) driver module the liquid crystal display (lcd) driver module generates the timing control to drive a static or multiplexed lcd panel. in the pic16f914/917 devices (pic16f914/917), the module drives the panels of up to four commons and up to 24 segments and in the pic16f913/916 devices (pic16f913/916), the module drives the panels of up to four commons and up to 16 segments. it also provides control of the lcd pixel data. the lcd driver module supports: ? direct driving of lcd panel ? three lcd clock sources with selectable prescaler ? up to four commons: - static - 1/2 multiplex - 1/3 multiplex - 1/4 multiplex ? up to 24 (in pic16f914/917 devices)/16 (in pic16f913/916 devices) segments ? static, 1/2 or 1/3 lcd bias the module has 32 registers: ? lcd control register (lcdcon) ? lcd phase register (lcdps) ? three lcd segment enable registers (lcdse<2:0>) ? 24 lcd data registers (lcddata<11:0>) the lcdcon register, shown in register 9-1, controls the operation of the lcd driver module. the lcdps register, shown in register 9-2, configures the lcd clock source prescaler and the type of waveform; type-a or type-b. the lcdse< 2:0> registers configure the functions of the port pins: ? lcdse0 se<7:0> ? lcdse1 se<15:8> ? lcdse2 se<23:16> as an example, lcdsen is detailed in register 9-3. once the module is initialized for the lcd panel, the individual bits of the lcddata<11:0> registers are cleared/set to represent a clear/dark pixel, respectively: ? lcddata0 seg7com0:seg0com0 ? lcddata1 seg15com0:seg8com0 ? lcddata2 seg23com0:seg16com0 ? lcddata3 seg7com1:seg0com1 ? lcddata4 seg15com1:seg8com1 ? lcddata5 seg23com1:seg16com1 ? lcddata6 seg7com2:seg0com2 ? lcddata7 seg15com2:seg8com2 ? lcddata8 seg23com2:seg16com2 ? lcddata9 seg7com3:seg0com3 ? lcddata10 seg15com3:seg8com3 ? lcddata11 seg23com3:seg16com3 as an example, lcddatax is detailed in register 9-4. once the module is configured, the lcden (lcdcon<7>) bit is used to enable or disable the lcd module. the lcd panel can also operate during sleep by clearing the slpen (lcdcon<6>) bit. note: the lcdse2 register is not implemented in pic16f913/916 devices. note: writing into the registers lcddata2, lcddata5, lcddata8 and lcddata11 in pic16f913/916 devices will not affect the status of any pixel and these registers can be used as general purpose registers.
PIC16F917/916/914/913 ds41250d-page 102 preliminary ? 2005 microchip technology inc. figure 9-1: lcd driver module block diagram com<3:0> clock source timing control data bus select and prescaler lfintosc/32 f osc /8192 t10sc/32 96 to 24 mux seg<23:0> to i/o pads (1) to i/o pads (1) lcdcon lcdps lcdsen 12 x 8 (= 4 x 24) lcddatax registers note 1: these are not directly connected to the i/o pads. see section 3.0 ?i/o ports? for more detail.
? 2005 microchip technology inc. preliminary ds41250d-page 103 PIC16F917/916/914/913 register 9-1: lcdcon ? liquid crystal display control register (address: 107h) r/w-0 r/w-0 r/c-0 r/w-1 r/w-0 r/w-0 r/w-1 r/w-1 lcden slpen werr vlcden cs1 cs0 lmux1 lmux0 bit 7 bit 0 bit 7 lcden: lcd driver enable bit 1 = lcd driver module is enabled 0 = lcd driver module is disabled bit 6 slpen: lcd driver enable in sleep mode bit 1 = lcd driver module is disabled in sleep mode 0 = lcd driver module is enabled in sleep mode bit 5 werr: lcd write failed error bit 1 = lcddatax register written while lcdps = 0 (must be cleared in software) 0 = no lcd write error bit 4 vlcden: lcd bias voltage pins enable bit 1 = vlcd pins are enabled 0 = vlcd pins are disabled bit 3-2 cs<1:0>: clock source select bits 00 = f osc /8192 01 = t1osc (timer1)/32 1x = lfintosc (31 khz)/32 bit 1-0 lmux<1:0>: commons select bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? c = only clearable bit ?1? = bit is set ?0? = bit is cleared x = bit is unknown - n = value at por lmux<1:0> multiplex maximum number of pixels (pic16f913/916) maximum number of pixels (pic16f914/917) bias 00 static (com0) 16 24 static 01 1/2 (com<1:0>) 32 48 1/2 or 1/3 10 1/3 (com<2:0>) 48 72 1/2 or 1/3 11 1/4 (com<3:0>) 60 (1) 96 1/3 note 1: on pic16f913/916 devices, com3 and seg15 are shared on one pin, limiting the device from driving 64 pixels.
PIC16F917/916/914/913 ds41250d-page 104 preliminary ? 2005 microchip technology inc. register 9-2: lcdps ? lcd prescaler select register (address: 108h) r/w-0 r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 wft biasmd lcda wa lp3 lp2 lp1 lp0 bit 7 bit 0 bit 7 wft: waveform type select bit 1 = type-b waveform (phase changes on each frame boundary) 0 = type-a waveform (phase changes within each common type) bit 6 biasmd: bias mode select bit when lmux<1:0> = 00 : 0 = static bias mode (do not set this bit to ? 1 ?) when lmux<1:0> = 01 : 1 = 1/2 bias mode 0 = 1/3 bias mode when lmux<1:0> = 10 : 1 = 1/2 bias mode 0 = 1/3 bias mode when lmux<1:0> = 11 : 0 = 1/3 bias mode (do not set this bit to ? 1 ?) bit 5 lcda: lcd active status bit 1 = lcd driver module is active 0 = lcd driver module is inactive bit 4 wa: lcd write allow status bit 1 = write into the lcddatax registers is allowed 0 = write into the lcddatax registers is not allowed bit 3-0 lp<3:0>: lcd prescaler select bits 1111 = 1:16 1110 = 1:15 1101 = 1:14 1100 = 1:13 1011 = 1:12 1010 = 1:11 1001 = 1:10 1000 = 1:9 0111 = 1:8 0110 = 1:7 0101 = 1:6 0100 = 1:5 0011 = 1:4 0010 = 1:3 0001 = 1:2 0000 = 1:1 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. preliminary ds41250d-page 105 PIC16F917/916/914/913 register 9-3: lcdsen ? lcd segment registers (address: 11ch, 11dh or 11eh) register 9-4: lcddatax ? lcd data registers (address: 110h-119h, 11ah, 11bh) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 sen sen sen sen sen sen sen sen bit 7 bit 0 bit 7-0 sen: segment enable bits 1 = segment function of the pin is enabled 0 = i/o function of the pin is enabled legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 segx- comy segx- comy segx- comy segx- comy segx- comy segx- comy segx- comy segx- comy bit 7 bit 0 bit 7-0 segx-comy: pixel on bits 1 = pixel on (dark) 0 = pixel off (clear) legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
PIC16F917/916/914/913 ds41250d-page 106 preliminary ? 2005 microchip technology inc. 9.1 lcd clock source selection the lcd driver module has 3 possible clock sources: ?f osc /8192 ?t1osc/32 ? lfintosc/32 the first clock source is the system clock divided by 8192 (f osc /8192). this divider ratio is chosen to provide about 1 khz output when the system clock is 8 mhz. the divider is not programmable. instead, the lcd prescaler bits, lcdps<3:0>, are used to set the lcd frame clock rate. the second clock source is the t1osc/32. this also gives about 1 khz when a 32.768 khz crystal is used with the timer1 oscillator. to use the timer1 oscillator as a clock source, the t1oscen (t1con<3>) bit should be set. the third clock source is the 31 khz lfintosc/32, which provides approximately 1 khz output. the second and third clock sources may be used to continue running the lcd while the processor is in sleep. using the bits, cs<1:0> (lcdcon<3:2>), any of these clock sources can be selected. 9.1.1 lcd prescaler a 16-bit counter is available as a prescaler for the lcd clock. the prescaler is not directly readable or writable; its value is set by the lp<3:0> bits (lcdps<3:0>), which determine the prescaler assignment and prescale ratio. the prescale values from 1:1 through 1:16. 9.2 lcd bias types the lcd driver module can be configured into three bias types: ? static bias (2 voltage levels: v ss and v dd ) ? 1/2 bias (3 voltage levels: v ss , 1/2 v dd and v dd ) ? 1/3 bias (4 voltage levels: v ss , 1/3 v dd , 2/3 v dd and v dd ) this module uses an external resistor ladder to generate the lcd bias voltages. the external resistor ladder should be connected to the bias 1 pin, bias 2 pin, bias 3 pin and v ss . the bias 3 pin should also be connected to v dd . figure 9-2 shows the proper way to connect the resistor ladder to the bias pins. figure 9-2: lcd bias resistor ladder connection diagram note: vlcd pins used to supply lcd bias voltage are enabled on power-up (por) and must be disabled by the user by clearing lcdcon<4>, the vlcden bit, (see register 9-1). v lcd 3 v lcd 2 v lcd 1 v lcd 0 (1) to lcd driver connections for external r-ladder 10 k * 10 k * 10 k * lcd bias 2 lcd bias 1 lcd bias 3 * these values are provided for design guidance only and should be optimized for the application by the designer. note 1: internal connection. v ss static bias 1/2 bias 1/3 bias v lcd 0v ss v ss v ss v lcd 1 ?1/2 v dd 1/3 v dd v lcd 2 ?1/2 v dd 2/3 v dd v lcd 3v dd v dd v dd 10 k *10k * v ss v dd * v dd * v dd * static bias 1/2 bias 1/3 bias
? 2005 microchip technology inc. preliminary ds41250d-page 107 PIC16F917/916/914/913 9.3 lcd multiplex types the lcd driver module can be configured into four multiplex types: ? static (only com0 used) ? 1/2 multiplex (com0 and com1 are used) ? 1/3 multiplex (com0, com1 and com2 are used) ? 1/4 multiplex (all com0, com1, com2 and com3 are used) the lmux<1:0> setting decides the function of rb5, ra2 or either ra3 or rd0 pins (see table 9-1 for details). if the pin is a digital i/o, the corresponding tris bit controls the data direction. if the pin is a com drive, then the tris setting of that pin is overridden. table 9-1: ra3, ra2, rb5 function 9.4 segment enables the lcdsen registers are used to select the pin function for each segment pin. the selection allows each pin to operate as either an lcd segment driver or as one of the pin?s alternate functions. to configure the pin as a segment pin, the corresponding bits in the lcdsen registers must be set to ? 1 ?. if the pin is a digital i/o, the corresponding tris bit controls the data direction. any bit set in the lcdsen registers overrides any bit settings in the corresponding tris register. 9.5 pixel control the lcddatax registers contain bits which define the state of each pixel. each bit defines one unique pixel. register 9-4 shows the correlation of each bit in the lcddatax registers to the respective common and segment signals. any lcd pixel location not being used for display can be used as general purpose ram. 9.6 lcd frame frequency the rate at which the com and seg outputs change is called the lcd frame frequency. table 9-2: frame frequency formulas table 9-3: approximate frame frequency (in hz) using f osc @ 8 mhz, timer1 @ 32.768 khz or intosc note: on a power-on reset, the lmux<1:0> bits are ? 11 ?. lmux <1:0> ra3/rd0 (1) ra2 rb5 00 digital i/o digital i/o digital i/o 01 digital i/o digital i/o com1 driver 10 digital i/o com2 driver com1 driver 11 com3 driver com2 driver com1 driver note 1: ra3 for pic16f913/916, rd0 for pic16f914/917 note: on a power-on reset, these pins are configured as digital i/o. multiplex frame frequency = static clock source/(4 x 1 x (lp<3:0> + 1)) 1/2 clock source/(2 x 2 x (lp<3:0> + 1)) 1/3 clock source/(1 x 3 x (lp<3:0> + 1)) 1/4 clock source/(1 x 4 x (lp<3:0> + 1)) note: clock source is f osc /8192, t1osc/32 or lfintosc/32. lp<3:0> static 1/2 1/3 1/4 2 85 85 114 85 364648564 451516851 543435743 637374937 732324332
PIC16F917/916/914/913 ds41250d-page 108 preliminary ? 2005 microchip technology inc. figure 9-3: lcd cl ock generation cs<1:0> t1osc 32 khz crystal osc. lfintosc nom f rc =31khz stat dup trip quad 4 lmux<1:0> 4-bit prog presc 1, 2, 3, 4 ring counter lmux<1:0> com0 com1 com2 com3 8192 f osc 2 32 32 lp<3:0> (lcdcon<3:2>) (lcdcon<1:0>) (lcdcon<1:0>) (lcdps<3:0>)
? 2005 microchip technology inc. preliminary ds41250d-page 109 PIC16F917/916/914/913 figure 9-4: lcd segment mapping worksheet lcd function com0 com1 com2 com3 pin no. port alternate functions lcddatax address lcd segment lcddatax address lcd segment lcddatax address lcd segment lcddatax address lcd segment 28/40-pin seg0 lcddata0, 0 lcddata3, 0 lcddata6, 0 lcddata9, 0 21/33 rb0 int seg1 lcddata0, 1 lcddata3, 1 lcddata6, 1 lcddata9, 1 22/34 rb1 seg2 lcddata0, 2 lcddata3, 2 lcddata6, 2 lcddata9, 2 23/35 rb2 seg3 lcddata0, 3 lcddata3, 3 lcddata6, 3 lcddata9, 3 24/36 rb3 seg4 lcddata0, 4 lcddata3, 4 lcddata6, 4 lcddata9, 4 6/6 ra4 c1out/t0cki seg5 lcddata0, 5 lcddata3, 5 lcddata6, 5 lcddata9, 5 7/7 ra5 c2out/an4/ss seg6 lcddata0, 6 lcddata3, 6 lcddata6, 6 lcddata9, 6 14/18 rc3 seg7 lcddata0, 7 lcddata3, 7 lcddata6, 7 lcddata9, 7 3/3 ra1 an1 seg8 lcddata1, 0 lcddata4, 0 lcddata7, 0 lcddata10, 0 18/26 rc7 rx/dt/sdi/sda seg9 lcddata1, 1 lcddata4, 1 lcddata7, 1 lcddata10, 1 17/25 rc6 tx/ck/sck/scl seg10 lcddata1, 2 lcddata4, 2 lcddata7, 2 lcddata10, 2 16/24 rc5 t1cki/ccp1 seg11 lcddata1, 3 lcddata4, 3 lcddata7, 3 lcddata10, 3 15/23 rc4 t1g /sdo seg12 lcddata1, 4 lcddata4, 4 lcddata7, 4 lcddata10, 4 2/2 ra0 an0 seg13 lcddata1, 5 lcddata4, 5 lcddata7, 5 lcddata10, 5 28/40 rb7 icspdat/icddat seg14 lcddata1, 6 lcddata4, 6 lcddata7, 6 lcddata10, 6 27/39 rb6 icspck/icdck seg15 lcddata1, 7 lcddata4, 7 lcddata7, 7 lcddata10, 7 5/5 ra3 an3/v ref + seg16 lcddata2, 0 lcddata5, 0 lcddata8, 0 lcddata11, 0 -/26 rd3 seg17 lcddata2, 1 lcddata5, 1 lcddata8, 1 lcddata11, 1 -/27 rd4 seg18 lcddata2, 2 lcddata5, 2 lcddata8, 2 lcddata11, 2 -/28 rd5 seg19 lcddata2, 3 lcddata5, 3 lcddata8, 3 lcddata11, 3 -/29 rd6 seg20 lcddata2, 4 lcddata5, 4 lcddata8, 4 lcddata11, 4 -/30 rd7 seg21 lcddata2, 5 lcddata5, 5 lcddata8, 5 lcddata11, 5 -/8 re0 an5 seg22 lcddata2, 6 lcddata5, 6 lcddata8, 6 lcddata11, 6 -/9 re1 an6 seg23 lcddata2, 7 lcddata5, 7 lcddata8, 7 lcddata11, 7 -/10 re2 an7 pic16f914/917 only.
PIC16F917/916/914/913 ds41250d-page 110 preliminary ? 2005 microchip technology inc. 9.7 lcd waveform generation lcd waveforms are generated so that the net ac voltage across the dark pixel should be maximized and the net ac voltage across the clear pixel should be minimized. the net dc voltage across any pixel should be zero. the com signal represents the time slice for each common, while the seg contains the pixel data. the pixel signal (com-seg) will have no dc compo- nent and it can take only one of the two rms values. the higher rms value will create a dark pixel and a lower rms value will create a clear pixel. as the number of commons increases, the delta between the two rms values decreases. the delta represents the maximum contrast that the display can have. the lcds can be driven by two types of waveform: type-a and type-b. in type-a waveform, the phase changes within each common type, whereas in type-b waveform, the phase changes on each frame boundary. thus, type-a waveform maintains 0 vdc over a single frame, whereas type-b waveform takes two frames. figure 9-5 through figure 9-15 provide waveforms for static, half-multiplex, one-third-multiplex and quarter-multiplex drives for type-a and type-b waveforms. figure 9-5: type-a/type-b waveforms in static drive note 1: if sleep has to be executed with lcd sleep enabled (lcdcon is ? 1 ?), then care must be taken to execute sleep only when v dc on all the pixels is ? 0 ?. 2: when the lcd clock source is f osc /8192, if sleep is executed, irrespective of the lcdcon setting, the lcd goes into sleep. thus, take care to see that v dc on all pixels is ? 0 ? when sleep is executed. v 1 v 0 com0 seg0 com0-seg0 com0-seg1 seg1 v 1 v 0 v 1 v 0 v 0 v 1 -v 1 v 0 1 frame com0 seg0 seg1 seg2 seg3 seg4 seg5 seg6 seg7
? 2005 microchip technology inc. preliminary ds41250d-page 111 PIC16F917/916/914/913 figure 9-6: type-a waveforms in 1/2 mux, 1/2 bias drive v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 -v 2 -v 1 v 2 v 1 v 0 -v 2 -v 1 com0 com1 seg0 seg1 com0-seg0 com0-seg1 1 frame com1 com0 seg0 seg1 seg2 seg3
PIC16F917/916/914/913 ds41250d-page 112 preliminary ? 2005 microchip technology inc. figure 9-7: type-b waveforms in 1/2 mux, 1/2 bias drive v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 -v 2 -v 1 v 2 v 1 v 0 -v 2 -v 1 com0 com1 seg0 seg1 com0-seg0 com0-seg1 com1 com0 seg0 seg1 seg2 seg3 2 frames
? 2005 microchip technology inc. preliminary ds41250d-page 113 PIC16F917/916/914/913 figure 9-8: type-a waveforms in 1/2 mux, 1/3 bias drive v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 com0 com1 seg0 seg1 com0-seg0 com0-seg1 1 frame com1 com0 seg0 seg1 seg2 seg3
PIC16F917/916/914/913 ds41250d-page 114 preliminary ? 2005 microchip technology inc. figure 9-9: type-b waveforms in 1/2 mux, 1/3 bias drive v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 com0 com1 seg0 seg1 com0-seg0 com0-seg1 com1 com0 seg0 seg1 seg2 seg3 2 frames
? 2005 microchip technology inc. preliminary ds41250d-page 115 PIC16F917/916/914/913 figure 9-10: type-a waveforms in 1/3 mux, 1/2 bias drive v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 -v 2 -v 1 v 2 v 1 v 0 -v 2 -v 1 com0 com1 com2 seg0 seg1 com0-seg0 com0-seg1 1 frame com2 com1 com0 seg0 seg1 seg2 seg2
PIC16F917/916/914/913 ds41250d-page 116 preliminary ? 2005 microchip technology inc. figure 9-11: type-b waveforms in 1/3 mux, 1/2 bias drive v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 v 2 v 1 v 0 -v 2 -v 1 v 2 v 1 v 0 -v 2 -v 1 com0 com1 com2 seg0 seg1 com0-seg0 com0-seg1 2 frames com2 com1 com0 seg0 seg1 seg2
? 2005 microchip technology inc. preliminary ds41250d-page 117 PIC16F917/916/914/913 figure 9-12: type-a waveforms in 1/3 mux, 1/3 bias drive v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 com0 com1 com2 seg0 seg1 com0-seg0 com0-seg1 1 frame com2 com1 com0 seg0 seg1 seg2 seg2
PIC16F917/916/914/913 ds41250d-page 118 preliminary ? 2005 microchip technology inc. figure 9-13: type-b waveforms in 1/3 mux, 1/3 bias drive v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 com0 com1 com2 seg0 seg1 com0-seg0 com0-seg1 2 frames com2 com1 com0 seg0 seg1 seg2
? 2005 microchip technology inc. preliminary ds41250d-page 119 PIC16F917/916/914/913 figure 9-14: type-a waveforms in 1/4 mux, 1/3 bias drive v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 com0 com1 com2 com3 seg0 seg1 com0-seg0 com0-seg1 com3 com2 com1 com0 1 frame seg0 seg1
PIC16F917/916/914/913 ds41250d-page 120 preliminary ? 2005 microchip technology inc. figure 9-15: type-b waveforms in 1/4 mux, 1/3 bias drive v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 v 3 v 2 v 1 v 0 -v 3 -v 2 -v 1 com0 com1 com2 com3 seg0 seg1 com0-seg0 com0-seg1 com3 com2 com1 com0 2 frames seg0 seg1
? 2005 microchip technology inc. preliminary ds41250d-page 121 PIC16F917/916/914/913 9.8 lcd interrupts the lcd timing generation provides an interrupt that defines the lcd frame timing. this interrupt can be used to coordinate the writing of the pixel data with the start of a new frame. writing pixel data at the frame boundary allows a visually crisp transition of the image. this interrupt can also be used to synchronize external events to the lcd. a new frame is defined to begin at the leading edge of the com0 common signal. the interrupt will be set immediately after the lcd controller completes accessing all pixel data required for a frame. this will occur at a fixed interval before the frame boundary (t fint ), as shown in figure 9-16. the lcd controller will begin to access data for the next frame within the interval from the interrupt to when the controller begins to access data after the interrupt (t fwr ). new data must be written within t fwr , as this is when the lcd controller will begin to access the data for the next frame. when the lcd driver is running with type-b waveforms and the lmux<1:0> bits are not equal to ? 00 ?, there are some additional issues that must be addressed. since the dc voltage on the pixel takes two frames to maintain zero volts, the pixel data must not change between subsequent frames. if the pixel data were allowed to change, the waveform for the odd frames would not necessarily be the complement of the waveform generated in the even frames and a dc component would be introduced into the panel. therefore, when using type-b waveforms, the user must synchronize the lcd pixel updates to occur within a subframe after the frame interrupt. to correctly sequence writing while in type-b, the interrupt will only occur on complete phase intervals. if the user attempts to write when the write is disabled, the werr (lcdcon<5>) bit is set. figure 9-16: waveforms and interrupt ti ming in quarter-duty cycle drive (example ? type-b, non-static) note: the interrupt is not generated when the type-a waveform is selected and when the type-b with no multiplex (static) is selected. frame boundary frame boundary lcd interrupt occurs controller accesses next frame data t fint t fwr t fwr =t frame /2*(lmux<1:0> + 1) + t cy /2 t fint =(t fwr /2 ? (2 t cy + 40 ns)) minimum = 1.5(t frame /4) ? (2 t cy + 40 ns) (t fwr /2 ? (1 t cy + 40 ns)) maximum = 1.5(t frame /4) ? (1 t cy + 40 ns) frame boundary v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 com0 com1 com2 com3 2 frames
PIC16F917/916/914/913 ds41250d-page 122 preliminary ? 2005 microchip technology inc. 9.9 operation during sleep the lcd module can operate during sleep. the selec- tion is controlled by bit slpen (lcdcon<6>). setting the slpen bit allows the lcd module to go to sleep. clearing the slpen bit allows the module to continue to operate during sleep. if a sleep instruction is executed and slpen = 1 , the lcd module will cease all functions and go into a very low-current consumption mode. the module will stop operation immediately and drive the minimum lcd voltage on both segment and common lines. figure 9-17 shows this operation. to ensure that no dc component is introduced on the panel, the sleep instruction should be executed imme- diately after a lcd frame boundary. the lcd interrupt can be used to determine the frame boundary. see section 9.8 ?lcd interrupts? for the formulas to calculate the delay. if a sleep instruction is executed and slpen = 0 , the module will continue to display the current contents of the lcddata registers. to allow the module to continue operation while in sleep, the clock source must be either the lfintosc or t1osc external oscillator. while in sleep, the lcd data cannot be changed. the lcd module current consumption will not decrease in this mode; however, the overall consumption of the device will be lower due to shut down of the core and other peripheral functions. table 9-4 shows the status of the lcd module during a sleep while using each of the three available clock sources: table 9-4: lcd module status during sleep clock source slpen operation during sleep? t1osc 0 yes 1 no lfintosc 0 yes 1 no f osc /4 0 no 1 no note: the lfintosc or external t1osc oscillator must be used to operate the lcd module during sleep.
? 2005 microchip technology inc. preliminary ds41250d-page 123 PIC16F917/916/914/913 figure 9-17: sleep entry/exit when slpen = 1 or cs<1:0> = 00 sleep instruction execution wake-up 2 frames v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 v 3 v 2 v 1 v 0 com0 com1 com2 seg0
PIC16F917/916/914/913 ds41250d-page 124 preliminary ? 2005 microchip technology inc. 9.10 configuring the lcd module the following is the sequence of steps to configure the lcd module. 1. select the frame clock prescale using bits lp<3:0> (lcdps<3:0>). 2. configure the appropriate pins to function as segment drivers using the lcdsen registers. 3. configure the lcd module for the following using the lcdcon register: -multiplex and bias mode, bits lmux<1:0> -timing source, bits cs<1:0> -sleep mode, bit slpen 4. write initial values to pixel data registers, lcddata0 through lcddata11. 5. clear lcd interrupt flag, lcdif (pir2<4>) and if desired, enable the interrupt by setting bit lcdie (pie2<4>). 6. enable bias voltage pins (vlcd<3:1>) by setting vlcden (lcdcon<4>). 7. enable the lcd module by setting bit lcden (lcdcon<7>). table 9-5: registers associated with lcd operation address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 10h t1con t1ginv t1ge t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0000 0000 uuuu uuuu 0bh/8bh/ 10bh/18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0dh pir2 osfif c2if c1if lcdif ? lvdif ? ccp2if 0000 -0-0 0000 -0-0 8dh pie2 osfie c2ie c1ie lcdie ? lvdie ? ccp2ie 0000 -0-0 0000 -0-0 107h lcdcon lcden slpen werr vlcden cs1 cs0 lmux1 lmux0 0001 0011 0001 0011 108h lcdps wft biasmd lcda wa lp3 lp2 lp1 lp0 0000 0000 0000 0000 110h lcddata0 seg7 com0 seg6 com0 seg5 com0 seg4 com0 seg3 com0 seg2 com0 seg1 com0 seg0 com0 xxxx xxxx uuuu uuuu 111h lcddata1 seg15 com0 seg14 com0 seg13 com0 seg12 com0 seg11 com0 seg10 com0 seg9 com0 seg8 com0 xxxx xxxx uuuu uuuu 112h lcddata2 (2) seg23 com0 seg22 com0 seg21 com0 seg20 com0 seg19 com0 seg18 com0 seg17 com0 seg16 com0 xxxx xxxx uuuu uuuu 113h lcddata3 seg7 com1 seg6 com1 seg5 com1 seg4 com1 seg3 com1 seg2 com1 seg1 com1 seg0 com1 xxxx xxxx uuuu uuuu 114h lcddata4 seg15 com1 seg14 com1 seg13 com1 seg12 com1 seg11 com1 seg10 com1 seg9 com1 seg8 com1 xxxx xxxx uuuu uuuu 115h lcddata5 (2) seg23 com1 seg22 com1 seg21 com1 seg20 com1 seg19 com1 seg18 com1 seg17 com1 seg16 com1 xxxx xxxx uuuu uuuu 116h lcddata6 seg7 com2 seg6 com2 seg5 com2 seg4 com2 seg3 com2 seg2 com2 seg1 com2 seg0 com2 xxxx xxxx uuuu uuuu 117h lcddata7 seg15 com2 seg14 com2 seg13 com2 seg12 com2 seg11 com2 seg10 com2 seg9 com2 seg8 com2 xxxx xxxx uuuu uuuu 118h lcddata8 (2) seg23 com2 seg22 com2 seg21 com2 seg20 com2 seg19 com2 seg18 com2 seg17 com2 seg16 com2 xxxx xxxx uuuu uuuu 119h lcddata9 seg7 com3 seg6 com3 seg5 com3 seg4 com3 seg3 com3 seg2 com3 seg1 com3 seg0 com3 xxxx xxxx uuuu uuuu 11ah lcddata10 seg15 com3 seg14 com3 seg13 com3 seg12 com3 seg11 com3 seg10 com3 seg9 com3 seg8 com3 xxxx xxxx uuuu uuuu 11bh lcddata11 (2) seg23 com3 seg22 com3 seg21 com3 seg20 com3 seg19 com3 seg18 com3 seg17 com3 seg16 com3 xxxx xxxx uuuu uuuu 11ch lcdse0 (3) se7 se6 se5 se4 se3 se2 se1 se0 0000 0000 uuuu uuuu 11dh lcdse1 (3) se15 se14 se13 se12 se11 se10 se9 se8 0000 0000 uuuu uuuu 11eh lcdse2 (2,3) se23 se22 se21 se20 se19 se18 se17 se16 0000 0000 uuuu uuuu legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by the lcd module. note 1: these pins may be configured as port pins, depending on the oscillator mode selected. 2: pic16f914/917 only. 3: this register is only initialized by a por or bor reset and is unchanged by other resets.
? 2005 microchip technology inc. preliminary ds41250d-page 125 PIC16F917/916/914/913 10.0 programmable low-voltage detect (plvd) module the programmable low-voltage detect module is an interrupt driven supply level detection. the voltage detection monitors the internal power supply. 10.1 voltage trip points the PIC16F917/916/914/913 device supports eight internal plvd trip points. see register 10-1 for avail- able plvd trip point voltages. 10.1.1 plvd calibration the pic16f91x stores the plvd calibration values in fuses located in the calibration word 2 (2009h). the calibration word 2 is not erased when using the spec- ified bulk erase sequence in the ?pic16f91x memory programming specification? (ds41244) and thus, does not require reprogramming. register 10-1: lvdcon ? low-voltage detect control register (address: 109h) u-0 u-0 r-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? ?irvstlvden ? lvdl2 lvdl1 lvdl0 bit 7 bit 0 bit 7-6 unimplemented: read as ? 0 ? bit 5 irvst: internal reference voltage stable status flag bit (1) 1 = indicates that the plvd is stable and plvd interrupt is reliable 0 = indicates that the plvd is not stable and plvd interrupt should not be enabled bit 4 lvden: low-voltage detect power enable bit 1 = enables plvd, powers up plvd circuit and supporting reference circuitry 0 = disables plvd, powers down plvd and supporting circuitry bit 3 unimplemented: read as ? 0 ? bit 2-0 lvdl<2:0>: low-voltage detection limit bits (nominal values) 111 = 4.5v 110 = 4.2v 101 = 4.0v 100 = 2.3v (default) 011 = 2.2v 010 = 2.1v 001 = 2.0v 000 = 1.9v (2) note 1: the irvst bit is usable only when the hfintosc is running. when using an external crystal to run the microcontroller, the plvd settling time is expected to be <50 s when v dd = 5v and <25 s when v dd = 3v. appropriate software delays should be used after enabling the plvd module to ensure proper status readings of the module. 2: not tested and below minimum v dd . legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
PIC16F917/916/914/913 ds41250d-page 126 preliminary ? 2005 microchip technology inc. table 10-1: registers associated with programmable low-voltage detect address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 0bh/8bh/ 10bh/18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0dh pir2 osfif c2if c1if lcdif ?lvdif ? ccp2if 0000 -0-0 0000 -0-0 8dh pie2 osfie c2ie c1ie lcdie ?lvdie ? ccp2ie 0000 -0-0 0000 -0-0 109h lvdcon ? ? irvst lvden ? lvdl2 lvdl1 lvdl0 --00 -100 --00 -100 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by the plvd module.
? 2005 microchip technology inc. preliminary ds41250d-page 127 PIC16F917/916/914/913 11.0 addressable universal synchronous asynchronous receiver transmitter (usart) the universal synchronous asynchronous receiver transmitter (usart) module is one of the two serial i/o modules. (usart is also known as a serial communications interface or sci.) the usart can be configured as a full-duplex asynchronous system that can communicate with peripheral devices, such as crt terminals and personal computers, or it can be configured as a half-duplex synchronous system that can communicate with peripheral devices, such as a/d or d/a integrated circuits, serial eeproms, etc. the usart can be configured in the following modes: ? asynchronous (full-duplex) ? synchronous ? master (half-duplex) ? synchronous ? slave (half-duplex) bit spen (rcsta<7>) and bits trisc<7:6> have to be set in order to configure pins rc6/tx/ck/sck/scl/seg9 and rc7/rx/dt/sdi/sda/seg8 as the universal synchronous asynchronous receiver transmitter. the usart module also has a multi-processor communication capability using 9-bit address detection. register 11-1: txsta ? transmit status and control register (address 98h) r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r-1 r/w-0 csrc tx9 txen sync ? brgh trmt tx9d bit 7 bit 0 bit 7 csrc: clock source select bit asynchronous mode: don?t care synchronous mode: 1 = master mode (clock generated internally from brg) 0 = slave mode (clock from external source) bit 6 tx9 : 9-bit transmit enable bit 1 = selects 9-bit transmission 0 = selects 8-bit transmission bit 5 txen : transmit enable bit 1 = transmit enabled 0 = transmit disabled note: sren/cren overrides txen in sync mode. bit 4 sync : usart mode select bit 1 = synchronous mode 0 = asynchronous mode bit 3 unimplemented: read as ? 0 ? bit 2 brgh : high baud rate select bit asynchronous mode: 1 = high speed 0 = low speed synchronous mode: unused in this mode bit 1 trmt : transmit shift register status bit 1 = tsr empty 0 = tsr full bit 0 tx9d: 9th bit of transmit data, can be parity bit legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
PIC16F917/916/914/913 ds41250d-page 128 preliminary ? 2005 microchip technology inc. register 11-2: rcsta ? receive status and control register (address 18h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r-0 r-x spen rx9 sren cren adden ferr oerr rx9d bit 7 bit 0 bit 7 spen (1) : serial port enable bit 1 = serial port enabled (configures rc7/rx/dt/sdi/sda/seg8 and rc6/tx/ck/sck/scl/seg9 pins as serial port pins) 0 = serial port disabled bit 6 rx9 : 9-bit receive enable bit 1 = selects 9-bit reception 0 = selects 8-bit reception bit 5 sren : single receive enable bit asynchronous mode: don?t care synchronous mode ? master: 1 = enables single receive 0 = disables single receive this bit is cleared after reception is complete synchronous mode ? slave: don?t care. bit 4 cren : continuous receive enable bit asynchronous mode: 1 = enables continuous receive 0 = disables continuous receive synchronous mode: 1 = enables continuous receive until enable bit cren is cleared (cren overrides sren) 0 = disables continuous receive bit 3 adden: address detect enable bit asynchronous mode 9-bit (rx9 = 1 ): 1 = enables address detection, enables interrupt and load of the receive buffer when rsr<8> is set 0 = disables address detection, all bytes are received and ninth bit can be used as parity bit bit 2 ferr : framing error bit 1 = framing error (can be updated by reading rcreg register and receive next valid byte) 0 = no framing error bit 1 oerr : overrun error bit 1 = overrun error (can be cleared by clearing bit cren) 0 = no overrun error bit 0 rx9d: 9th bit of received data (can be parity bit but must be calculated by user firmware) note 1: ccp2con used for pic16f914/917 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. preliminary ds41250d-page 129 PIC16F917/916/914/913 11.1 usart baud rate generator (brg) the brg supports both the asynchronous and synchronous modes of the usart. it is a dedicated 8-bit baud rate generator. the spbrg register controls the period of a free running 8-bit timer. in asynchronous mode, bit brgh (txsta<2>) also controls the baud rate. in synchronous mode, bit brgh is ignored. table 11-1 shows the formula for computation of the baud rate for different usart modes which only apply in master mode (internal clock). given the desired baud rate and f osc , the nearest integer value for the spbrg register can be calculated using the formula in table 11-1. from this, the error in baud rate can be determined. it may be advantageous to use the high baud rate (brgh = 1 ) even for slower baud clocks. this is because the f osc /(16 (x + 1)) equation can reduce the baud rate error in some cases. writing a new value to the spbrg register causes the brg timer to be reset (or cleared). this ensures the brg does not wait for a timer overflow before outputting the new baud rate. 11.1.1 sampling the data on the rc7/rx/dt/sdi/sda/seg8 pin is sampled three times by a majority detect circuit to determine if a high or a low level is present at the rx pin. table 11-1: baud rate formula table 11-2: registers associated with baud rate generator sync brgh = 0 (low speed) brgh = 1 (high speed) 0 1 (asynchronous) baud rate = f osc /(64 (x + 1)) (synchronous) baud rate = f osc /(4 (x + 1)) baud rate = f osc /(16 (x + 1)) n/a legend: x = value in spbrg (0 to 255) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 98h txsta csrc tx9 txen sync ?brgh trmt tx9d 0000 -010 0000 -010 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as ? 0 ?. shaded cells are not used by the brg.
PIC16F917/916/914/913 ds41250d-page 130 preliminary ? 2005 microchip technology inc. table 11-3: baud rates for asynchronous mode (brgh = 0 ) baud rate (k) f osc = 20 mhz f osc = 16 mhz f osc = 10 mhz kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) 0.3??????? ?? 1.2 1.221 1.75 255 1.202 0.17 207 1.202 0.17 129 2.4 2.404 0.17 129 2.404 0.17 103 2.404 0.17 64 9.6 9.766 1.73 31 9.615 0.16 25 9.766 1.73 15 19.2 19.531 1.72 15 19.231 0.16 12 19.531 1.72 7 28.8 31.250 8.51 9 27.778 3.55 8 31.250 8.51 4 33.6 34.722 3.34 8 35.714 6.29 6 31.250 6.99 4 57.6 62.500 8.51 4 62.500 8.51 3 52.083 9.58 2 high 1.221 ? 255 0.977 ? 255 0.610 ? 255 low 312.500 ? 0 250.000 ? 0 156.250 ? 0 baud rate (k) f osc = 4 mhz f osc = 3.6864 mhz kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) 0.3 0.300 0 207 0.3 0 191 1.2 1.202 0.17 51 1.2 0 47 2.4 2.404 0.17 25 2.4 0 23 9.6 8.929 6.99 6 9.6 0 5 19.2 20.833 8.51 2 19.2 0 2 28.8 31.250 8.51 1 28.8 0 1 33.6 ? ? ? ? ? ? 57.6 62.500 8.51 0 57.6 0 0 high 0.244 ? 255 0.225 ? 255 low 62.500 ? 0 57.6 ? 0 table 11-4: baud rates for asynchronous mode (brgh = 1 ) baud rate (k) f osc = 20 mhz f osc = 16 mhz f osc = 10 mhz kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) 0.3????????? 1.2????????? 2.4 ? ? ? ? ? ? 2.441 1.71 255 9.6 9.615 0.16 129 9.615 0.16 103 9.615 0.16 64 19.2 19.231 0.16 64 19.231 0.16 51 19.531 1.72 31 28.8 29.070 0.94 42 29.412 2.13 33 28.409 1.36 21 33.6 33.784 0.55 36 33.333 0.79 29 32.895 2.10 18 57.6 59.524 3.34 20 58.824 2.13 16 56.818 1.36 10 high 4.883 ? 255 3.906 ? 255 2.441 - 255 low 1250.000 ? 0 1000.000 ? 0 625.000 - 0 baud rate (k) f osc = 4 mhz f osc = 3.6864 mhz kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) 0.3?????? 1.2 1.202 0.17 207 1.2 0 191 2.4 2.404 0.17 103 2.4 0 95 9.6 9.615 0.16 25 9.6 0 23 19.2 19.231 0.16 12 19.2 0 11 28.8 27.798 3.55 8 28.8 0 7 33.6 35.714 6.29 6 32.9 2.04 6 57.6 62.500 8.51 3 57.6 0 3 high 0.977 ? 255 0.9 ? 255 low 250.000 ? 0 230.4 ? 0
? 2005 microchip technology inc. preliminary ds41250d-page 131 PIC16F917/916/914/913 11.2 usart asynchronous mode in this mode, the usart uses standard non-return-to-zero (nrz) format (one start bit, eight or nine data bits and one stop bit). the most common data format is 8 bits. an on-chip, dedicated, 8-bit baud rate generator can be used to derive standard baud rate frequencies from the oscillator. the usart transmits and receives the lsb first. the transmitter and receiver are functionally independent but use the same data format and baud rate. the baud rate generator produces a clock, either x16 or x64 of the bit shift rate, depending on bit brgh (txsta<2>). parity is not supported by the hardware, but can be implemented in software (and stored as the ninth data bit). asynchronous mode is stopped during sleep. asynchronous mode is selected by clearing bit sync (txsta<4>). the usart asynchronous module consists of the following important elements: ? baud rate generator ? sampling circuit ? asynchronous transmitter ? asynchronous receiver 11.2.1 usart asynchronous transmitter the usart transmitter block diagram is shown in figure 11-1. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer, txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the stop bit has been transmitted from the previous load. as soon as the stop bit is transmitted, the tsr is loaded with new data from the txreg register (if available). once the txreg register transfers the data to the tsr register (occurs in one t cy ), the txreg register is empty and flag bit, txif (pir1<4>), is set. this interrupt can be enabled/disabled by setting/clearing enable bit, txie (pie1<4>). flag bit txif will be set regardless of the state of enable bit txie and cannot be cleared in soft- ware. it will reset only when new data is loaded into the txreg register. while flag bit txif indicates the status of the txreg register, another bit, trmt (txsta<1>), shows the status of the tsr register. status bit trmt is a read-only bit which is set when the tsr register is empty. no interrupt logic is tied to this bit so the user has to poll this bit in order to determine if the tsr register is empty. transmission is enabled by setting enable bit, txen (txsta<5>). the actual transmission will not occur until the txreg register has been loaded with data and the baud rate generator (brg) has produced a shift clock (figure 11-2). the transmission can also be started by first loading the txreg register and then setting enable bit txen. normally, when transmission is first started, the tsr register is empty. at that point, transfer to the txreg register will result in an immediate transfer to tsr, resulting in an empty txreg. a back-to-back transfer is thus possible (figure 11-3). clearing enable bit txen during a transmission will cause the transmission to be aborted and will reset the transmitter. as a result, the rc6/tx/ck/sck/scl/seg9 pin will revert to high-impedance. in order to select 9-bit transmission, transmit bit tx9 (txsta<6>) should be set and the ninth bit should be written to tx9d (txsta<0>). the ninth bit must be written before writing the 8-bit data to the txreg reg- ister. this is because a data write to the txreg regis- ter can result in an immediate transfer of the data to the tsr register (if the tsr is empty). in such a case, an incorrect ninth data bit may be loaded in the tsr register. when setting up an asynchronous transmission, follow these steps: 1. initialize the spbrg register for the appropriate baud rate. if a high-speed baud rate is desired, set bit brgh ( section 11.1 ?usart baud rate generator (brg)? ). 2. enable the asynchronous serial port by clearing bit sync and setting bit spen. 3. if interrupts are desired, then set enable bit txie. 4. if 9-bit transmission is desired, then set transmit bit tx9. 5. enable the transmission by setting bit txen, which will also set bit txif. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. load data to the txreg register (starts transmission). 8. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set. note 1: the tsr register is not mapped in data memory, so it is not available to the user. 2: flag bit txif is set when enable bit txen is set. txif is cleared by loading txreg.
PIC16F917/916/914/913 ds41250d-page 132 preliminary ? 2005 microchip technology inc. figure 11-1: usart transmit block diagram figure 11-2: asynchronous master transmission figure 11-3: asynchronous master transmission (back-to-back) txif txie interrupt txen baud rate clk spbrg baud rate generator tx9d msb lsb data bus txreg register tsr register (8) 0 tx9 trmt spen rc6/tx/ck/sck/ pin buffer and control 8 ? ? ? scl/seg9 pin word 1 stop bit word 1 transmit shift reg start bit bit 0 bit 1 bit 7/8 write to txreg word 1 brg output (shift clock) rc6/tx/ck/ txif bit (transmit buffer reg. empty flag) trmt bit (transmit shift reg. empty flag) sck/scl/seg9 transmit shift reg. write to txreg brg output (shift clock) rc6/tx/ck/ txif bit (interrupt reg. flag) trmt bit (transmit shift reg. empty flag) word 1 word 2 word 1 word 2 start bit stop bit start bit transmit shift reg. word 1 word 2 bit 0 bit 1 bit 7/8 bit 0 note: this timing diagram shows tw o consecutive transmissions. sck/scl/seg9
? 2005 microchip technology inc. preliminary ds41250d-page 133 PIC16F917/916/914/913 table 11-5: registers associated with asynchronous transmission address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 19h txreg usart transmit data register 0000 0000 0000 0000 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous transmission.
PIC16F917/916/914/913 ds41250d-page 134 preliminary ? 2005 microchip technology inc. 11.2.2 usart asynchronous receiver the receiver block diagram is shown in figure 11-4. the data is received on the rc7/rx/dt/sdi/sda/seg8 pin and drives the data recovery block. the data recovery block is actually a high-speed shifter, operating at x16 times the baud rate; whereas the main receive serial shifter operates at the bit rate or at f osc . once asynchronous mode is selected, reception is enabled by setting bit cren (rcsta<4>). the heart of the receiver is the receive (serial) shift register (rsr). after sampling the stop bit, the received data in the rsr is transferred to the rcreg register (if it is empty). if the transfer is complete, flag bit, rcif (pir1<5>), is set. the actual interrupt can be enabled/disabled by setting/clearing enable bit, rcie (pie1<5>). flag bit rcif is a read-only bit which is cleared by the hardware. it is cleared when the rcreg register has been read and is empty. the rcreg is a double-buffered register (i.e., it is a two-deep fifo). it is possible for two bytes of data to be received and transferred to the rcreg fifo and a third byte to begin shifting to the rsr register. on the detection of the stop bit of the third byte, if the rcreg register is still full, the overrun error bit, oerr (rcsta<1>), will be set. the word in the rsr will be lost. the rcreg register can be read twice to retrieve the two bytes in the fifo. overrun bit oerr has to be cleared in soft- ware. this is done by resetting the receive logic (cren is cleared and then set). if bit oerr is set, transfers from the rsr register to the rcreg register are inhib- ited and no further data will be received. it is, therefore, essential to clear error bit oerr if it is set. framing error bit, ferr (rcsta<2>), is set if a stop bit is detected as clear. bit ferr and the 9th receive bit are buffered the same way as the receive data. reading the rcreg will load bits rx9d and ferr with new values, therefore, it is essential for the user to read the rcsta register before reading the rcreg register in order not to lose the old ferr and rx9d information. when setting up an asynchronous reception, follow these steps: 1. initialize the spbrg register for the appropriate baud rate. if a high-speed baud rate is desired, set bit brgh ( section 11.1 ?usart baud rate generator (brg)? ). 2. enable the asynchronous serial port by clearing bit sync and setting bit spen. 3. if interrupts are desired, then set enable bit rcie. 4. if 9-bit reception is desired, then set bit rx9. 5. enable the reception by setting bit cren. 6. flag bit rcif will be set when reception is com- plete and an interrupt will be generated if enable bit rcie is set. 7. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 8. read the 8-bit received data by reading the rcreg register. 9. if any error occurred, clear the error by clearing enable bit cren. 10. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set.
? 2005 microchip technology inc. preliminary ds41250d-page 135 PIC16F917/916/914/913 figure 11-4: usart receive block diagram figure 11-5: asynchronous reception table 11-6: registers associated with asynchronous reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg usart receive data register 0000 0000 0000 0000 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 98h txsta csrc tx9 txen sync ?brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous reception. x64 baud rate clk spbrg baud rate generator rc7/rx/dt/ pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcreg register fifo interrupt rcif rcie data bus 8 64 16 or stop start (8) 7 1 0 rx9 ? ? ? f osc sdi/sda/seg8 start bit bit 7/8 bit 1 bit 0 bit 7/8 bit 0 stop bit start bit start bit bit 7/8 stop bit rx (pin) reg rcv buffer reg rcv shift read rcv buffer reg rcreg rcif (interrupt flag) oerr bit cren word 1 rcreg word 2 rcreg stop bit note: this timing diagram shows three words appearing on the rx input. the rcreg (receive buffer) is read after the third word, causing the oerr (overrun error) bit to be set.
PIC16F917/916/914/913 ds41250d-page 136 preliminary ? 2005 microchip technology inc. 11.2.3 setting up 9-bit mode with address detect when setting up an asynchronous reception with address detect enabled: ? initialize the spbrg register for the appropriate baud rate. if a high-speed baud rate is desired, set bit brgh. ? enable the asynchronous serial port by clearing bit sync and setting bit spen. ? if interrupts are desired, then set enable bit rcie. ? set bit rx9 to enable 9-bit reception. ? set adden to enable address detect. ? enable the reception by setting enable bit cren. ? flag bit rcif will be set when reception is complete, and an interrupt will be generated if enable bit rcie was set. ? read the rcsta register to get the ninth bit and determine if any error occurred during reception. ? read the 8-bit received data by reading the rcreg register to determine if the device is being addressed. ? if any error occurred, clear the error by clearing enable bit cren. ? if the device has been addressed, clear the adden bit to allow data bytes and address bytes to be read into the receive buffer and interrupt the cpu. figure 11-6: usart receive block diagram x64 baud rate clk spbrg baud rate generator rc7/rx/dt pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcreg register fifo interrupt rcif rcie data bus 8 64 16 or stop start (8) 7 10 rx9 ? ? ? rx9 adden rx9 adden rsr<8> enable load of receive buffer 8 8 f osc sdi/sda/seg8
? 2005 microchip technology inc. preliminary ds41250d-page 137 PIC16F917/916/914/913 figure 11-7: asynchronous reception with address detect figure 11-8: asynchronous reception with address byte first table 11-7: registers associated with asynchronous reception start bit bit 1 bit 0 bit 8 bit 0 stop bit start bit bit 8 stop bit rc7/rx/dt/ load rsr read rcif word 1 rcreg bit 8 = 0 , data byte bit 8 = 1 , address byte note: this timing diagram shows a data byte followed by an address byte. the data byte is not read into the rcreg (receive buffer) because adden = 1 . sdi/sda/seg8 start bit bit 1 bit 0 bit 8 bit 0 stop bit start bit bit 8 stop bit load rsr read rcif word 1 rcreg bit 8 = 1 , address byte bit 8 = 0 , data byte note: this timing diagram shows a data byte followed by an address byte. the data byte is not read into the rcreg (receive buffer) because adden was not updated and still = 0 . rc7/rx/dt/ sdi/sda/seg8 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg usart receive data register 0000 0000 0000 0000 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 98h txsta csrc tx9 txen sync ?brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous reception.
PIC16F917/916/914/913 ds41250d-page 138 preliminary ? 2005 microchip technology inc. 11.3 usart synchronous master mode in synchronous master mode, the data is transmitted in a half-duplex manner (i.e., transmission and reception do not occur at the same time). when transmitting data, the reception is inhibited and vice versa. synchronous mode is entered by setting bit, sync (txsta<4>). in addition, enable bit, spen (rcsta<7>), is set in order to configure the rc6/tx/ck/sck/scl/seg9 and rc7/rx/dt/sdi/sda/seg8 i/o pins to ck (clock) and dt (data) lines, respectively. the master mode indi- cates that the processor transmits the master clock on the ck line. the master mode is entered by setting bit, csrc (txsta<7>). 11.3.1 usart synchronous master transmission the usart transmitter block diagram is shown in figure 11-6. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register, txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the last bit has been transmitted from the previous load. as soon as the last bit is transmitted, the tsr is loaded with new data from the txreg (if available). once the txreg register transfers the data to the tsr register (occurs in one t cycle ), the txreg is empty and inter- rupt bit, txif (pir1<4>), is set. the interrupt can be enabled/disabled by setting/clearing enable bit txie (pie1<4>). flag bit txif will be set regardless of the state of enable bit txie and cannot be cleared in soft- ware. it will reset only when new data is loaded into the txreg register. while flag bit txif indicates the status of the txreg register, another bit, trmt (txsta<1>), shows the status of the tsr register. trmt is a read-only bit which is set when the tsr is empty. no interrupt logic is tied to this bit so the user has to poll this bit in order to determine if the tsr register is empty. the tsr is not mapped in data memory so it is not available to the user. transmission is enabled by setting enable bit, txen (txsta<5>). the actual transmission will not occur until the txreg register has been loaded with data. the first data bit will be shifted out on the next available rising edge of the clock on the ck line. data out is stable around the falling edge of the synchronous clock (figure 11-9). the transmission can also be started by first loading the txreg register and then setting bit txen (figure 11-10). this is advantageous when slow baud rates are selected, since the brg is kept in reset when bits txen, cren and sren are clear. setting enable bit txen will start the brg, creating a shift clock immediately. normally, when transmission is first started, the tsr register is empty, so a transfer to the txreg register will result in an immediate transfer to tsr, resulting in an empty txreg. back-to-back transfers are possible. clearing enable bit txen during a transmission will cause the transmission to be aborted and will reset the transmitter. the dt and ck pins will revert to high-impedance. if either bit cren or bit sren is set during a transmission, the transmission is aborted and the dt pin reverts to a high-impedance state (for a reception). the ck pin will remain an output if bit csrc is set (internal clock). the transmitter logic, however, is not reset, although it is disconnected from the pins. in order to reset the transmitter, the user has to clear bit txen. if bit sren is set (to interrupt an on-going trans- mission and receive a single word), then after the sin- gle word is received, bit sren will be cleared and the serial port will revert back to transmitting, since bit txen is still set. the dt line will immediately switch from high-impedance receive mode to transmit and start driving. to avoid this, bit txen should be cleared. in order to select 9-bit transmission, the tx9 (txsta<6>) bit should be set and the ninth bit should be written to bit tx9d (txsta<0>). the ninth bit must be written before writing the 8-bit data to the txreg register. this is because a data write to the txreg can result in an immediate transfer of the data to the tsr register (if the tsr is empty). if the tsr was empty and the txreg was written before writing the ?new? tx9d, the ?present? value of bit tx9d is loaded. steps to follow when setting up a synchronous master transmission: 1. initialize the spbrg register for the appropriate baud rate ( section 11.1 ?usart baud rate generator (brg)? ). 2. enable the synchronous master serial port by setting bits sync, spen and csrc. 3. if interrupts are desired, set enable bit txie. 4. if 9-bit transmission is desired, set bit tx9. 5. enable the transmission by setting bit txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. start transmission by loading data to the txreg register. 8. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set.
? 2005 microchip technology inc. preliminary ds41250d-page 139 PIC16F917/916/914/913 table 11-8: registers associated with synchronous master transmission figure 11-9: synchronous transmission figure 11-10: synchronous transmission (through txen) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 19h txreg usart transmit data register 0000 0000 0000 0000 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous master transmission. bit 0 bit 1 bit 7 word 1 q1q2q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 bit 2 bit 0 bit 1 bit 7 rc6/tx/ck/ write to txreg reg txif bit (interrupt flag) txen bit ? 1 ? ? 1 ? word 2 trmt bit write word 1 write word 2 note: sync master mode; spbrg = 0 . continuous transmission of two 8-bit words. sck/scl/seg9 rc7/rx/dt/ sdi/sda/seg8 rc7/rx/dt/sdi/sda/seg8 rc6/tx/ck/sck/scl/seg9 write to txreg reg txif bit trmt bit bit 0 bit 1 bit 2 bit 6 bit 7 txen bit
PIC16F917/916/914/913 ds41250d-page 140 preliminary ? 2005 microchip technology inc. 11.3.2 usart synchronous master reception once synchronous mode is selected, reception is enabled by setting either enable bit, sren (rcsta<5>), or enable bit, cren (rcsta<4>). data is sampled on the rc7/rx/dt/sdi/sda/seg8 pin on the falling edge of the clock. if enable bit sren is set, then only a single word is received. if enable bit cren is set, the reception is continuous until cren is cleared. if both bits are set, cren takes precedence. after clocking the last bit, the received data in the receive shift register (rsr) is transferred to the rcreg register (if it is empty). when the transfer is complete, interrupt flag bit, rcif (pir1<5>), is set. the actual interrupt can be enabled/disabled by set- ting/clearing enable bit, rcie (pie1<5>). flag bit rcif is a read-only bit which is reset by the hardware. in this case, it is reset when the rcreg register has been read and is empty. the rcreg is a double-buffered register (i.e., it is a two-deep fifo). it is possible for two bytes of data to be received and transferred to the rcreg fifo and a third byte to begin shifting into the rsr register. on the clocking of the last bit of the third byte, if the rcreg register is still full, then overrun error bit, oerr (rcsta<1>), is set. the word in the rsr will be lost. the rcreg register can be read twice to retrieve the two bytes in the fifo. bit oerr has to be cleared in software (by clearing bit cren). if bit oerr is set, transfers from the rsr to the rcreg are inhibited so it is essential to clear bit oerr if it is set. the ninth receive bit is buffered the same way as the receive data. reading the rcreg register will load bit rx9d with a new value, therefore, it is essential for the user to read the rcsta register before reading rcreg in order not to lose the old rx9d information. when setting up a synchronous master reception: 1. initialize the spbrg register for the appropriate baud rate ( section 11.1 ?usart baud rate generator (brg)? ). 2. enable the synchronous master serial port by setting bits sync, spen and csrc. 3. ensure bits cren and sren are clear. 4. if interrupts are desired, then set enable bit rcie. 5. if 9-bit reception is desired, then set bit rx9. 6. if a single reception is required, set bit sren. for continuous reception, set bit cren. 7. interrupt flag bit rcif will be set when reception is complete and an interrupt will be generated if enable bit rcie was set. 8. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 9. read the 8-bit received data by reading the rcreg register. 10. if any error occurred, clear the error by clearing bit cren. 11. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set. table 11-9: registers associated with synchronous master reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg usart receive data register 0000 0000 0000 0000 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous master reception.
? 2005 microchip technology inc. preliminary ds41250d-page 141 PIC16F917/916/914/913 figure 11-11: synchronous reception (master mode, sren) 11.4 usart synchronous slave mode synchronous slave mode differs from the master mode in the fact that the shift clock is supplied externally at the rc6/tx/ck/sck/scl/seg9 pin (instead of being supplied internally in master mode). this allows the device to transfer or receive data while in sleep mode. slave mode is entered by clearing bit, csrc (txsta<7>). 11.4.1 usart synchronous slave transmit the operation of the synchronous master and slave modes is identical, except in the case of the sleep mode. if two words are written to the txreg and then the sleep instruction is executed, the following will occur: a) the first word will immediately transfer to the tsr register and transmit. b) the second word will remain in txreg register. c) flag bit txif will not be set. d) when the first word has been shifted out of tsr, the txreg register will transfer the second word to the tsr and flag bit txif will now be set. e) if enable bit txie is set, the interrupt will wake the chip from sleep and if the global interrupt is enabled, the program will branch to the interrupt vector (0004h). when setting up a synchronous slave transmission, follow these steps: 1. enable the synchronous slave serial port by set- ting bits sync and spen and clearing bit csrc. 2. clear bits cren and sren. 3. if interrupts are desired, then set enable bit txie. 4. if 9-bit transmission is desired, then set bit tx9. 5. enable the transmission by setting enable bit txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. start transmission by loading data to the txreg register. 8. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set. cren bit rc7/rx/dt/ rc6/tx/ck/ write to bit sren sren bit rcif bit (interrupt) read rxreg note: timing diagram demonstrates sync master mode with bit sren = 1 and bit brg = 0 . q3 q4q1q2 q3q4q1q2q3q4 q2 q1q2q3q4q1q2q3q4 q1q2q3q4q1q2q3q4 q1q2q3q4q1q2q3q4 q1q2q3q4 ? 0 ? bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7 ? 0 ? q1q2q3q4 sdi/sda/seg8 sck/scl/seg9
PIC16F917/916/914/913 ds41250d-page 142 preliminary ? 2005 microchip technology inc. table 11-10: registers associated with synchronous slave transmission 11.4.2 usart synchronous slave reception the operation of the synchronous master and slave modes is identical, except in the case of the sleep mode. bit sren is a ?don't care? in slave mode. if receive is enabled by setting bit cren prior to the sleep instruction, then a word may be received during sleep. on completely receiving the word, the rsr register will transfer the data to the rcreg register and if enable bit rcie bit is set, the interrupt generated will wake the chip from sleep. if the global interrupt is enabled, the program will branch to the interrupt vector (0004h). when setting up a synchronous slave reception, follow these steps: 1. enable the synchronous master serial port by setting bits sync and spen and clearing bit csrc. 2. if interrupts are desired, set enable bit rcie. 3. if 9-bit reception is desired, set bit rx9. 4. to enable reception, set enable bit cren. 5. flag bit rcif will be set when reception is complete and an interrupt will be generated if enable bit rcie was set. 6. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 7. read the 8-bit received data by reading the rcreg register. 8. if any error occurred, clear the error by clearing bit cren. 9. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set. table 11-11: registers associated with synchronous slave reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 19h txreg usart transmit data register 0000 0000 0000 0000 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous slave transmission. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg usart receive data register 0000 0000 0000 0000 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous slave reception.
? 2005 microchip technology inc. preliminary ds41250d-page 143 PIC16F917/916/914/913 12.0 analog-to-digital converter (a/d) module the analog-to-digital converter (a/d) allows conversion of an analog input signal to a 10-bit binary representation of that signal. the PIC16F917/916/914/913 has up to eight analog inputs, multiplexed into one sample and hold circuit. the output of the sample and hold is connected to the input of the converter. the converter generates a binary result via successive approximation and stores the result in a 10-bit register. the voltage reference used in the conversion is software selectable to either v dd or a voltage applied by the v ref pin. figure 12-1 shows the block diagram of the a/d on the PIC16F917/916/914/913. figure 12-1: a/d block diagram ra0/an0/c1-/seg12 a/d ra1/an1/c2-/seg7 ra2/an2/c2+/v ref -/com2 ra5/an4/c2out/ss /seg5 v dd v ref + adon go/done vcfg0 = 1 vcfg0 = 0 chs<2:0> adresh adresl 10 10 adfm v ss re0/an5/seg21 (1) re1/an6/seg22 (1) re2/an7/seg23 (1) ra3/an3/c1+/v ref +/com3 (2) /seg15 vcfg1 = 1 vcfg1 = 0 v ref - note 1: these channels are only available on pic16f914/917 devices. 2: com3 available on ra3 only on pic16f913/916 devices.
PIC16F917/916/914/913 ds41250d-page 144 preliminary ? 2005 microchip technology inc. 12.1 a/d configuration and operation there are three registers available to control the functionality of the a/d module: 1. ansel (register 12-1) 2. adcon0 (register 12-2) 3. adcon1 (register 12-3) 12.1.1 analog port pins the ans<7:0> bits (ansel<7:0>) and the tris bits control the operation of the a/d port pins. set the corresponding tris bits to set the pin output driver to its high-impedance state. likewise, set the correspond- ing ansel bit to disable the digital input buffer. 12.1.2 channel selection there are up to eight analog channels on the PIC16F917/916/914/913, an<7:0>. the chs<2:0> bits (adcon0<4:2>) control which channel is connected to the sample and hold circuit. 12.1.3 voltage reference there are two options for each reference to the a/d converter, v ref + and v ref -. v ref + can be connected to either v dd or an externally applied voltage. alternatively, v ref - can be connected to either v ss or an externally applied voltage. vcfg<1:0> bits are used to select the reference source. 12.1.4 conversion clock the a/d conversion cycle requires 11 t ad . the source of the conversion clock is software selectable via the adcs bits (adcon1<6:4>). there are seven possible clock options: ?f osc /2 ?f osc /4 ?f osc /8 ?f osc /16 ?f osc /32 ?f osc /64 ?f rc (dedicated internal oscillator) for correct conversion, the a/d conversion clock (1/t ad ) must be selected to ensure a minimum t ad of 1.6 s. table 12-1 shows a few t ad calculations for selected frequencies. table 12-1: t ad vs. device operating frequencies note: analog voltages on any pin that is defined as a digital input may cause the input buffer to conduct excess current. a/d clock source (t ad ) device frequency operation adcs<2:0> 20 mhz 5 mhz 4 mhz 1.25 mhz 2 t osc 000 100 ns (2) 400 ns (2) 500 ns (2) 1.6 s 4 t osc 100 200 ns (2) 800 ns (2) 1.0 s (2) 3.2 s 8 t osc 001 400 ns (2) 1.6 s2.0 s6.4 s 16 t osc 101 800 ns (2) 3.2 s4.0 s 12.8 s (3) 32 t osc 010 1.6 s6.4 s 8.0 s (3) 25.6 s (3) 64 t osc 110 3.2 s 12.8 s (3) 16.0 s (3) 51.2 s (3) a/d rc x11 2-6 s (1,4) 2-6 s (1,4) 2-6 s (1,4) 2-6 s (1,4) legend: shaded cells are outside of recommended range. note 1: the a/d rc source has a typical t ad time of 4 s for v dd > 3.0v. 2: these values violate the minimum required t ad time. 3: for faster conversion times, the selection of another clock source is recommended. 4: when the device frequency is greater than 1 mhz, the a/d rc clock source is only recommended if the conversion will be performed during sleep.
? 2005 microchip technology inc. preliminary ds41250d-page 145 PIC16F917/916/914/913 12.1.5 starting a conversion the a/d conversion is initiated by setting the go/done bit (adcon0<1>). when the conversion is complete, the a/d module: ? clears the go/done bit ? sets the adif flag (pir1<6>) ? generates an interrupt (if enabled) if the conversion must be aborted, the go/done bit can be cleared in software. the adresh:adresl registers will not be updated with the partially complete a/d conversion sample. instead, the adresh:adresl registers will retain the value of the previous conversion. after an aborted conversion, a 2t ad delay is required before another acquisition can be initiated. following the delay, an input acquisition is automatically started on the selected channel. figure 12-2: a/d conversion t ad cycles 12.1.6 conversion output the a/d conversion can be supplied in two formats: left or right shifted. the adfm bit (adcon0<7>) controls the output format. figure 12-3 shows the output formats. figure 12-3: 10-bit a/d result format note: the go/done bit should not be set in the same instruction that turns on the a/d. t ad 1 t ad 2 t ad 3 t ad 4 t ad 5 t ad 6 t ad 7 t ad 8 t ad 9 set go/done bit holding capacitor is disconnected from analog input (typically 100 ns) b9 b8 b7 b6 b5 b4 b3 b2 t ad 10 t ad 11 b1 b0 t cy to t ad conversion starts adresh and adresl registers are loaded, go/done bit is cleared, adif bit is set, holding capacitor is connected to analog input adresh adresl (adfm = 0 )msb lsb bit 7 bit 0 bit 7 bit 0 10-bit a/d result unimplemented: read as ? 0 ? (adfm = 1 ) msb lsb bit 7 bit 0 bit 7 bit 0 unimplemented: read as ? 0 ? 10-bit a/d result
PIC16F917/916/914/913 ds41250d-page 146 preliminary ? 2005 microchip technology inc. register 12-1: ansel ? analog select register (address: 91h) register 12-2: adcon0 ? a/d control register (address: 1fh) r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 ans7 (2) ans6 (2) ans5 (2) ans4 ans3 ans2 ans1 ans0 bit 7 bit 0 bit 7-0: ans<7:0> : analog select bits (2) select between analog or digital function on pins an<7:0>, respectively. 1 = analog input. pin is assigned as analog input. (1) 0 = digital i/o. pin is assigned to port or special function. note 1: setting a pin to an analog input automatically disables the digital input circuitry, weak pull-ups, and interrupt-on-change if available. the corresponding tris bit must be set to input mode in order to allow external control of the voltage on the pin. 2: ans<7:5> on pic16f914/917 only; forced ? 0 ? on pic16f913/916. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 adfm vcfg1 vcfg0 chs2 chs1 chs0 go/done adon bit 7 bit 0 bit 7 adfm: a/d result formed select bit 1 = right justified 0 = left justified bit 6 vcfg1: voltage reference bit 1 = v ref - pin 0 = v ss bit 5 vcfg0: voltage reference bit 1 = v ref + pin 0 = v dd bit 4-2 chs<2:0>: analog channel select bits 000 = channel 00 (an0) 001 = channel 01 (an1) 010 = channel 02 (an2) 011 = channel 03 (an3) 100 = channel 04 (an4) 101 = channel 05 (an5) 110 = channel 06 (an6) 111 = channel 07 (an7) bit 1 go/done : a/d conversion status bit 1 = a/d conversion cycle in progress. setting this bit starts an a/d conversion cycle. this bit is automatically cleared by hardware when the a/d conversion has completed. 0 = a/d conversion completed/not in progress bit 0 adon: a/d conversion status bit 1 = a/d converter module is operating 0 = a/d converter is shut off and consumes no operating current legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. preliminary ds41250d-page 147 PIC16F917/916/914/913 register 12-3: adcon1 ? a/d control register 1 (address: 9fh) u-0 r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? adcs2 adcs1 adcs0 ? ? ? ? bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6-4 adcs<2:0>: a/d conversion clock select bits 000 =f osc /2 001 =f osc /8 010 =f osc /32 x11 =f rc (clock derived from a dedicated internal oscillator = 500 khz max) 100 =f osc /4 101 =f osc /16 110 =f osc /64 bit 3-0 unimplemented: read as ? 0 ? legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
PIC16F917/916/914/913 ds41250d-page 148 preliminary ? 2005 microchip technology inc. 12.1.7 configuring the a/d after the a/d module has been configured as desired, the selected channel must be acquired before the conversion is started. the analog input channels must have their corresponding tris bits selected as inputs. to determine sample time, see section 19.0 ?electrical specifications? . after this sample time has elapsed, the a/d conversion can be started. these steps should be followed for an a/d conversion: 1. configure the a/d module: ? configure analog/digital i/o (ansel) ? configure voltage reference (adcon0) ? select a/d input channel (adcon0) ? select a/d conversion clock (adcon1) ? turn on a/d module (adcon0) 2. configure a/d interrupt (if desired): ? clear adif bit (pir1<6>) ? set adie bit (pie1<6>) ? set peie and gie bits (intcon<7:6>) 3. wait the required acquisition time. 4. start conversion: ? set go/done bit (adcon0<1>) 5. wait for a/d conversion to complete, by either: ? polling for the go/done bit to be cleared (with interrupts disabled); or ? waiting for the a/d interrupt 6. read a/d result register pair (adresh:adresl); clear bit adif if required. 7. for next conversion, go to step 1 or step 2 as required. the a/d conversion time per bit is defined as t ad . a minimum wait of 2 t ad is required before the next acquisition starts. example 12-1: a/d conversion ;this code block configures the a/d ;for polling, vdd reference, r/c clock ;and ra0 input. ; ;conversion start and wait for complete ;polling code included. ; bsf status,rp0 ;bank 1 movlw b?01110000? ;a/d rc clock movwf adcon1 bsf trisa,0 ;set ra0 to input bsf ansel,0 ;set ra0 to analog bcf status,rp0 ;bank 0 movlw b?10000001? ;right, vdd vref, an0 movwf adcon0 call sampletime ;wait min sample time bsf adcon0,go ;start conversion btfsc adcon0,go ;is conversion done? goto $-1 ;no, test again movf adresh,w ;read upper 2 bits movwf resulthi bsf status,rp0 ;bank 1 movf adresl,w ;read lower 8 bits movwf resultlo
? 2005 microchip technology inc. preliminary ds41250d-page 149 PIC16F917/916/914/913 12.2 a/d acquisition requirements for the a/d converter to meet its specified accuracy, the charge holding capacitor (c hold ) must be allowed to fully charge to the input channel voltage level. the analog input model is shown in figure 12-4. the source impedance (r s ) and the internal sampling switch (r ss ) impedance directly affect the time required to charge the capacitor c hold . the sampling switch (r ss ) impedance varies over the device voltage (v dd ), see figure 12-4. the maximum recom- mended impedance for analog sources is 10 k . as the impedance is decreased, the acquisition time may be decreased. after the analog input channel is selected (changed), this acquisition must be done before the conversion can be started. to calculate the minimum acquisition time, equation 12-1 may be used. this equation assumes that 1/2 lsb error is used (1024 steps for the a/d). the 1/2 lsb error is the maximum error allowed for the a/d to meet its specified resolution. to calculate the minimum acquisition time, t acq , see the ? picmicro ? mid-range mcu family reference manual ? (ds33023). equation 12-1: acquisition time t acq amplifier settling time hold capacitor charging time temperature coefficient ++ = t amp t c t coff ++ = 2s t c temperature - 25c () 0.05s/c () [] ++ = t c c hold r ic r ss r s ++ () ln(1/2047) ? = 10pf 1k 7k 10k ++ () ? ln(0.0004885) = 1.37 = s t acq 2 s 1.37 s 50c- 25c () 0.05 s /c () [] ++ = 4.67 s = v applied 1 e tc ? rc --------- ? ?? ?? ?? v applied 1 1 2047 ----------- - ? ?? ?? = v applied 1 1 2047 ----------- - ? ?? ?? v chold = v applied 1 e t c ? rc --------- - ? ?? ?? ?? v chold = ;[1] v chold charged to within 1/2 lsb ;[2] v chold charge response to v applied ;combining [1] and [2] where c hold is charged to within 1/2 lsb: solving for t c : therefore: note 1: the reference voltage (v ref ) has no effect on the equation, since it cancels itself out. 2: the charge holding capacitor (c hold ) is not discharged after each conversion. 3: the maximum recommended impedance for analog sources is 10 k . this is required to meet the pin leakage specification.
PIC16F917/916/914/913 ds41250d-page 150 preliminary ? 2005 microchip technology inc. figure 12-4: analog input model 12.3 a/d operation during sleep the a/d converter module can operate during sleep. this requires the a/d clock source to be set to the internal oscillator. when the rc clock source is selected, the a/d waits one instruction before starting the conversion. this allows the sleep instruction to be executed, thus eliminating much of the switching noise from the conversion. when the conversion is complete, the go/done bit is cleared and the result is loaded into the adresh:adresl registers. if the a/d interrupt is enabled, the device awakens from sleep. if the gie bit (intcon<7>) is set, the program counter is set to the interrupt vector (0004h). if gie is clear, the next instruction is executed. if the a/d interrupt is not enabled, the a/d module is turned off, although the adon bit remains set. when the a/d clock source is something other than rc, a sleep instruction causes the present conversion to be aborted, and the a/d module is turned off. the adon bit remains set. figure 12-5: a/d transfer function c pin va r s anx 5 pf v dd v t = 0.6v v t = 0.6v i leakage r ic 1k sampling switch ss r ss c hold = dac capacitance v ss 6v sampling switch 5v 4v 3v 2v 567891011 (k ) v dd = 10 pf 500 na legend: c pin v t i leakage r ic ss c hold = input capacitance = threshold voltage = leakage current at the pin due to = interconnect resistance = sampling switch = sample/hold capacitance (from dac) various junctions r ss 3ffh 3feh a/d output 3fdh 3fch 004h 003h 002h 001h 000h full-scale 3fbh 1/2 lsb ideal zero-scale zero-scale transition v ref 1/2 lsb ideal transition center of full-scale code 1 lsb ideal full-scale range analog input
? 2005 microchip technology inc. preliminary ds41250d-page 151 PIC16F917/916/914/913 12.4 effects of reset a device reset forces all registers to their reset state. thus, the a/d module is turned off and any pending conversion is aborted. the adresh:adresl registers are unchanged. table 12-2: summary of a/d registers addr name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 05h porta ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 xxxx xxxx uuuu uuuu 09h porte ? ? ? ?re3 re2 re1 re0 ---- xxxx ---- uuuu 0bh/ 8bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 1eh adresh most significant 8 bits of the left justified a/d result or 2 bits of the right justified result xxxx xxxx uuuu uuuu 1fh adcon0 adfm vcfg1 vcfg0 chs2 chs1 chs0 go/done adon 0000 0000 0000 0000 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 89h trise ? ? ? ? trise3 trise2 trise1 trise0 ---- 1111 ---- 1111 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 91h ansel ans7 ans6 ans5 ans4 ans3 ans2 ans1 ans0 1111 1111 1111 1111 9eh adresl least significant 2 bits of the left justified a/d result or 8 bits of the right justified result xxxx xxxx uuuu uuuu 9fh adcon1 ? adcs2 adcs1 adcs0 ? ? ? ? -000 ---- -000 ---- legend: x = unknown, u = unchanged, - = unimplemented read as ? 0 ?. shaded cells are not used for a/d module.
PIC16F917/916/914/913 ds41250d-page 152 preliminary ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. preliminary ds41250d-page 153 PIC16F917/916/914/913 13.0 data eeprom and flash program memory control data eeprom memory is readable and writable and the flash program memory is readable during normal operation (full v dd range). these memories are not directly mapped in the register file space. instead, they are indirectly addressed through the special function registers. there are six sfrs used to access these memories: ? eecon1 ? eecon2 ? eedatl ? eedath ? eeadrl ? eeadrh when interfacing the data memory block, eedatl holds the 8-bit data for read/write, and eeadrl holds the address of the ee data location being accessed. this device has 256 bytes of data eeprom with an address range from 0h to 0ffh. when interfacing the program memory block, the eedatl and eedath registers form a 2-byte word that holds the 14-bit data for read, and the eeadrl and eeadrh registers form a 2-byte word that holds the 13-bit address of the eeprom location being accessed. this device has 4k and 8k words of program eeprom with an address range from 0h-0fffh and 0h-1fffh. the program memory allows one word reads. the eeprom data memory allows byte read and write. a byte write automatically erases the location and writes the new data (erase before write). the write time is controlled by an on-chip timer. the write/erase voltages are generated by an on-chip charge pump rated to operate over the voltage range of the device for byte or word operations. when the device is code-protected, the cpu may continue to read and write the data eeprom memory and read the program memory. when code-protected, the device programmer can no longer access data or program memory. additional information on the data eeprom is available in the ? picmicro ? mid-range mcu family reference manual ? (ds33023). 13.1 eeadrl and eeadrh registers the eeadrl and eeadrh registers can address up to a maximum of 256 bytes of data eeprom or up to a maximum of 8k words of program eeprom. when selecting a program address value, the msb of the address is written to the eeadrh register and the lsb is written to the eeadrl register. when selecting a data address value, only the lsb of the address is written to the eeadrl register. 13.1.1 eecon1 and eecon2 registers eecon1 is the control register for ee memory accesses. control bit eepgd determines if the access will be a program or data memory access. when clear, as it is when reset, any subsequent operations will operate on the data memory. when set, any subsequent operations will operate on the program memory. program memory can only be read. control bits rd and wr initiate read and write, respectively. these bits cannot be cleared, only set, in software. they are cleared in hardware at completion of the read or write operation. the inability to clear the wr bit in software prevents the accidental, premature termination of a write operation. the wren bit, when set, will allow a write operation to data eeprom. on power-up, the wren bit is clear. the wrerr bit is set when a write operation is interrupted by a mclr or a wdt time-out reset during normal operation. in these situations, following reset, the user can check the wrerr bit and rewrite the location. the data and address will be unchanged in the eedatl and eeadrl registers. interrupt flag bit eeif (pir1<7>), is set when write is complete. it must be cleared in the software. eecon2 is not a physical register. reading eecon2 will read all ? 0 ?s. the eecon2 register is used exclusively in the data eeprom write sequence.
PIC16F917/916/914/913 ds41250d-page 154 preliminary ? 2005 microchip technology inc. register 13-1: eedatl ? eeprom data low byte register (address: 10ch) register 13-2: eeadrl ? eeprom address low byte register (address: 10dh) register 13-3: eedath ? eeprom data high byte register (address: 10eh) register 13-4: eeadrh ? eeprom address high byte register (address: 10fh) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 eedatl7 eedatl6 eedatl5 eedatl4 eedatl3 eedatl2 eedatl1 eedatl0 bit 7 bit 0 bit 7-0 eedatl<7:0> : byte value to write to or read from data eeprom bits or to read from program memory legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 eeadrl7 eeadrl6 eeadrl5 eeadrl4 eeadrl3 eeadrl2 eeadrl1 eeadrl0 bit 7 bit 0 bit 7-0 eeadrl<7:0> : specifies one of 256 locations for eeprom read/write operation bits or low byte for program memory reads legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? eedath5 eedath4 eedath3 eedath2 eedath1 eedath0 bit 7 bit 0 bit 5-0 eedath<5:0> : byte value to write to or read from data eeprom bits or to read from program memory legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? eeadrh4 eeadrh3 eeadrh2 eeadrh1 eeadrh0 bit 7 bit 0 bit 4-0 eeadrh<4:0> : specifies one of 256 locations for eeprom read/write operation bits or high bits for program memory reads legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. preliminary ds41250d-page 155 PIC16F917/916/914/913 register 13-5: eecon1 ? eeprom control register 1 (address: 18ch) r/w-0 u-0 u-0 u-0 r/w-x r/w-0 r/s-0 r/s-0 eepgd ? ? ? wrerr wren wr rd bit 7 bit 0 bit 7 eepgd: program/data eeprom select bit 1 = accesses program memory 0 = accesses data memory bit 6-4 unimplemented: read as ? 0 ? bit 3 wrerr: eeprom error flag bit 1 = a write operation is prematurely terminated (any mclr reset, any wdt reset during normal operation or bor reset) 0 = the write operation completed bit 2 wren: eeprom write enable bit 1 = allows write cycles 0 = inhibits write to the data eeprom bit 1 wr : write control bit eepgd = 1 : this bit is ignored eepgd = 0 : 1 = initiates a write cycle (the bit is cleared by hard ware once write is complete. the wr bit can only be set, not cleared, in software.) 0 = write cycle to the data eeprom is complete bit 0 rd : read control bit 1 = initiates a memory read (rd is cleared in hardware. the rd bit can only be set, not cleared, in software.) 0 = does not initiate an memory read legend: s = bit can only be set r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
PIC16F917/916/914/913 ds41250d-page 156 preliminary ? 2005 microchip technology inc. 13.1.2 reading the data eeprom memory to read a data memory location, the user must write the address to the eeadrl register, clear the eepgd control bit (eecon1<7>), and then set control bit rd (eecon1<0>). the data is available in the very next cycle, in the eedatl register; therefore, it can be read in the next instruction. eedatl will hold this value until another read or until it is written to by the user (during a write operation). example 13-1: data eeprom read 13.1.3 writing to the data eeprom memory to write an eeprom data location, the user must first write the address to the eeadrl register and the data to the eedatl register. then the user must follow a specific sequence to initiate the write for each byte. the write will not initiate if the sequence described below is not followed exactly (write 55h to eecon2, write aah to eecon2, then set wr bit) for each byte. interrupts should be disabled during this code segment. additionally, the wren bit in eecon1 must be set to enable write. this mechanism prevents accidental writes to data eeprom due to errant (unexpected) code execution (i.e., lost programs). the user should keep the wren bit clear at all times, except when updating eeprom. the wren bit is not cleared by hardware. after a write sequence has been initiated, clearing the wren bit will not affect this write cycle. the wr bit will be inhibited from being set unless the wren bit is set. at the completion of the write cycle, the wr bit is cleared in hardware and the ee write complete interrupt flag bit (eeif) is set. the user can either enable this interrupt or poll this bit. eeif must be cleared by software. the steps to write to eeprom data memory are: 1. if step 10 is not implemented, check the wr bit to see if a write is in progress. 2. write the address to eeadr. make sure that the address is not larger than the memory size of the device. 3. write the 8-bit data value to be programmed in the eedata register. 4. clear the eepgd bit to point to eeprom data memory. 5. set the wren bit to enable program operations. 6. disable interrupts (if enabled). 7. execute the special five instruction sequence: ? write 55h to eecon2 in two steps (first to w, then to eecon2) ? write aah to eecon2 in two steps (first to w, then to eecon2) ? set the wr bit 8. enable interrupts (if using interrupts). 9. clear the wren bit to disable program operations. 10. at the completion of the write cycle, the wr bit is cleared and the eeif interrupt flag bit is set. (eeif must be cleared by firmware.) if step 1 is not implemented, then firmware should check for eeif to be set, or wr to clear, to indicate the end of the program cycle. example 13-2: data eeprom write bsf status,rp1 ; bcf status,rp0 ; bank 2 movf data_ee_addr,w ; data memory movwf eeadr ; address to read bsf status,rp0 ; bank 3 bcf eecon1,eepgd ; point to data ; memory bsf eecon1,rd ; ee read bcf status,rp0 ; bank 2 movf eedata,w ; w = eedata bsf status,rp1 ; bsf status,rp0 btfsc eecon1,wr ;wait for write goto $-1 ;to complete bcf status,rp0 ;bank 2 movf data_ee_addr,w;data memory movwf eeadr ;address to write movf data_ee_data,w;data memory value movwf eedata ;to write bsf status,rp0 ;bank 3 bcf eecon1,eepgd ;point to data ;memory bsf eecon1,wren ;enable writes bcf intcon,gie ;disable ints. movlw 55h ; movwf eecon2 ;write 55h movlw aah ; movwf eecon2 ;write aah bsf eecon1,wr ;set wr bit to ;begin write bsf intcon,gie ;enable ints. bcf eecon1,wren ;disable writes required sequence
? 2005 microchip technology inc. preliminary ds41250d-page 157 PIC16F917/916/914/913 13.1.4 reading the flash program memory to read a program memory location, the user must write two bytes of the address to the eeadrl and eeadrh registers, set the eepgd control bit (eecon1<7>), and then set control bit rd (eecon1<0>). once the read control bit is set, the program memory flash controller will use the second instruction cycle to read the data. this causes the second instruction immediately following the ? bsf eecon1,rd ? instruction to be ignored. the data is available in the very next cycle, in the eedatl and eedath registers; therefore, it can be read as two bytes in the following instructions. eedatl and eedath registers will hold this value until another read or until it is written to by the user (during a write operation). example 13-3: flash program read note 1: the two instructions following a program memory read are required to be nop ?s. this prevents the user from executing a two-cycle instruction on the next instruction after the rd bit is set. 2: if the wr bit is set when eepgd = 1 , it will be immediately reset to ? 0 ? and no operation will take place. bsf status, rp1 ; bcf status, rp0 ; bank 2 movlw ms_prog_ee_addr; movwf eeadrh ; ms byte of program address to read movlw ls_prog_ee_addr; movwf eeadr ; ls byte of program address to read bsf status, rp0 ; bank 3 bsf eecon1, eepgd ; point to program memory bsf eecon1, rd ; ee read ; nop nop ; any instructions here are ignored as program ; memory is read in second cycle after bsf eecon1,rd ; bcf status, rp0 ; bank 2 movf eedata, w ; w = ls byte of program eedata movwf datal ; movf eedath, w ; w = ms byte of program eedata movwf datah ; required sequence
PIC16F917/916/914/913 ds41250d-page 158 preliminary ? 2005 microchip technology inc. figure 13-1: flash program me mory read cycle execution table 13-1: registers/bits associated with data eeprom addr name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 0bh/8bh/ 10bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 10ch eedatl eedatl7 eedatl6 eedatl5 eedatl4 eedatl3 eedatl2 eedatl1 eedatl0 0000 0000 0000 0000 10dh eeadrl eeadrl7 eeadrl6 eeadrl5 eeadrl4 eeadrl3 eeadrl2 eeadrl1 eeadrl0 0000 0000 0000 0000 10eh eedath ? ? eedath5 eedath4 eedath3 eedath2 eedath1 eedath0 --00 0000 --00 0000 10fh eeadrh ? ? ? eeadrh4 eeadrh3 eeadrh2 eeadrh1 eeadrh0 ---0 0000 ---0 0000 18ch eecon1 eepgd ? ? ? wrerr wren wr rd 0--- x000 ---- q000 18dh eecon2 eeprom control register 2 (not a physical register) ---- ---- ---- ---- legend: x = unknown, u = unchanged, - = unimplemented read as ? 0 ?, q = value depends upon condition. shaded cells are not used by data eeprom module. q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 bsf eecon1,rd executed here instr(pc + 1) executed here forced nop executed here pc pc + 1 eeadrh,eeadrl pc+3 pc + 5 flash addr rd bit eedath,eedatl p c + 3 pc + 4 instr (pc + 1) instr(pc - 1) executed here instr(pc + 3) executed here instr(pc + 4) executed here flash data eedath eedatl register eerhlt instr (pc) instr (pc + 3) instr (pc + 4)
? 2005 microchip technology inc. preliminary ds41250d-page 159 PIC16F917/916/914/913 14.0 ssp module overview the synchronous serial port (ssp) module is a serial interface used to communicate with other peripheral or microcontroller devices. these peripheral devices may be serial eeproms, shift registers, display drivers, a/d converters, etc. the ssp module can operate in one of two modes: ? serial peripheral interface (spi?) ? inter-integrated circuit (i 2 c ? ) an overview of i 2 c operations and additional information on the ssp module can be found in the ? picmicro ? mid-range mcu family reference manual ? (ds33023). refer to application note an578, ? use of the ssp module in the multi-master environment ? (ds00578). 14.1 spi mode this section contains register definitions and operational characteristics of the spi module. additional information on the spi module can be found in the ? picmicro ? mid-range mcu family reference manual ? (ds33023). the spi mode allows 8 bits of data to be synchronously transmitted and received simultaneously. to accomplish communication, typically three pins are used: ? serial data out (sdo) ? rc4/t1g /sdo/seg11 ? serial data in (sdi) ? rc7/rx/dt/sdi/sda/seg8 ? serial clock (sck) ? rc6/tx/ck/sck/scl/seg9 additionally, a fourth pin may be used when in a slave mode of operation: ? slave select (ss ) ? ra5/an4/c2out/ss /seg5 when initializing the spi, several options need to be specified. this is done by programming the appropriate control bits in the sspcon register (sspcon<5:0>) and sspstat<7:6>. these control bits allow the following to be specified: ? master mode (sck is the clock output) ? slave mode (sck is the clock input) ? clock polarity (idle state of sck) ? clock edge (output data on rising/falling edge of sck) ? clock rate (master mode only) ? slave select mode (slave mode only)
PIC16F917/916/914/913 ds41250d-page 160 preliminary ? 2005 microchip technology inc. register 14-1: sspstat ? sync serial port status re gister (address 94h) r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke d/a psr/w ua bf bit 7 bit 0 bit 7 smp : spi? data input sample phase bit spi master mode: 1 = input data sampled at end of data output time 0 = input data sampled at middle of data output time (microwire) spi slave mode: smp must be cleared when spi is used in slave mode i 2 c ? mode: this bit must be maintained clear bit 6 cke : spi clock edge select bit spi mode, ckp = 0 : 1 = data transmitted on falling edge of sck 0 = data transmitted on rising edge of sck (microwire alternate) spi mode, ckp = 1 : 1 = data transmitted on rising edge of sck 0 = data transmitted on falling edge of sck (microwire default) i 2 c mode: this bit must be maintained clear bit 5 d/a : data/address bit (i 2 c m ode only) 1 = indicates that the last byte received or transmitted was data 0 = indicates that the last byte received or transmitted was address bit 4 p : stop bit (i 2 c mode only) this bit is cleared when the ssp module is disabled, or when the start bit is detected last. sspen is cleared. 1 = indicates that a stop bit has been detected last (this bit is ? 0 ? on reset) 0 = stop bit was not detected last bit 3 s : start bit (i 2 c mode only) this bit is cleared when the ssp module is disabled, or when the stop bit is detected last. sspen is cleared. 1 = indicates that a start bit has been detected last (this bit is ? 0 ? on reset) 0 = start bit was not detected last bit 2 r/w : read/write bit information (i 2 c mode only) this bit holds the r/w bit information following the last address match. this bit is only valid from the address match to the next start bit, stop bit or ack bit. 1 = read 0 = write bit 1 ua : update address bit (10-bit i 2 c mode only) 1 = indicates that the user needs to update the address in the sspadd register 0 = address does not need to be updated bit 0 bf : buffer full status bit receive (spi and i 2 c modes): 1 = receive complete, sspbuf is full 0 = receive not complete, sspbuf is empty transmit (i 2 c mode only): 1 = transmit in progress, sspbuf is full 0 = transmit complete, sspbuf is empty legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. preliminary ds41250d-page 161 PIC16F917/916/914/913 register 14-2: sspcon ? sync serial port control register (address 14h) r/w-0r/w-0r/w-0r/w-0r/w-0r/w-0r/w-0r/w-0 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 bit 7 bit 0 bit 7 wcol : write collision detect bit 1 = the sspbuf register is written while it is still transmitting the previous word (must be cleared in software) 0 = no collision bit 6 sspov : receive overflow indicator bit in spi ? mode: 1 = a new byte is received while the sspbuf register is still holding the previous data. in case of overflow, the data in sspsr is lost. overflow can only occur in slave mode. the user must read the sspbuf, even if only transmitting data, to avoid setting overflow. in master mode, the over- flow bit is not set since each new reception (and transmission) is initiated by writing to the ssp- buf register. 0 = no overflow i n i 2 c ? mode: 1 = a byte is received while the sspbuf register is still holding the previous byte. sspov is a ?don?t care? in transmit mode. sspov must be cleared in software in either mode. 0 = no overflow bit 5 sspen : synchronous serial port enable bit in spi mode: 1 = enables serial port and configures sck, sdo, and sdi as serial port pins 0 = disables serial port and configures these pins as i/o port pins in i 2 c mode: 1 = enables the serial port and configures the sda and scl pins as serial port pins 0 = disables serial port and configures these pins as i/o port pins in both modes, when enabled, these pins must be properly configured as input or output. bit 4 ckp : clock polarity select bit in spi mode: 1 = idle state for clock is a high level (microwire default) 0 = idle state for clock is a low level (microwire alternate) in i 2 c mode: sck release control 1 = enable clock 0 = holds clock low (clock stretch). (used to ensure data setup time.) bit 3-0 sspm<3:0> : synchronous serial port mode select bits 0000 = spi master mode, clock = f osc /4 0001 = spi master mode, clock = f osc /16 0010 = spi master mode, clock = f osc /64 0011 = spi master mode, clock = tmr2 output/2 0100 = spi slave mode, clock = sck pin. ss pin control enabled. 0101 = spi slave mode, clock = sck pin. ss pin control disabled. ss can be used as i/o pin. 0110 = i 2 c slave mode, 7-bit address 0111 = i 2 c slave mode, 10-bit address 1011 = i 2 c firmware controlled master mode (slave idle) 1110 = i 2 c slave mode, 7-bit address with start and stop bit interrupts enabled 1111 = i 2 c slave mode, 10-bit address with start and stop bit interrupts enabled legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
PIC16F917/916/914/913 ds41250d-page 162 preliminary ? 2005 microchip technology inc. figure 14-1: ssp block diagram (spi mode) to enable the serial port, sspen bit (sspcon<5>) must be set. to reset or reconfigure spi mode: ? clear bit sspen ? re-initialize the sspcon register ? set sspen bit this configures the sdi, sdo, sck and ss pins as serial port pins. for the pins to behave in a serial port function, they must have their data direction bits (in the trisc register) appropriately programmed. this is: ? sdi must have trisc<7> set ? sdo must have trisc<4> cleared ? sck (master mode) must have trisc<6> cleared ? sck (slave mode) must have trisc<6> set ?ss must have trisa<5> set. read write internal data bus rc7/rx/ rc4/t1g / ra5/an2/ rc6/tx/ck/ sspsr reg sspbuf reg sspm<3:0> bit 0 shift clock ss control enable edge select clock select tmr2 outpu t t cy prescaler 4, 16, 64 trisc<6> 2 edge select 2 4 scl/ peripheral oe sda/seg8 dt/sdi/ sdo/seg11 c2out/ss / seg5 sck/ seg9 note 1: when the spi is in slave mode with ss pin control enabled (sspcon<3:0> = 0100 ), the spi module will reset if the ss pin is set to v dd . 2: if the spi is used in slave mode with cke = 1, then the ss pin control must be enabled. 3: when the spi is in slave mode with ss pin control enabled (sspcon<3:0> = 0100 ), the state of the ss pin can affect the state read back from the trisc<4> bit. the peripheral oe signal from the ssp module into portc controls the state that is read back from the trisc<4> bit (see section 19.4 ?dc characteristics: PIC16F917/916/914/913-i (industrial) PIC16F917/916/914/913-e (extended)? for information on portc). if read-modify-write instructions, such as bsf, are performed on the trisc register while the ss pin is high, this will cause the trisc<4> bit to be set, thus disabling the sdo output.
? 2005 microchip technology inc. preliminary ds41250d-page 163 PIC16F917/916/914/913 14.2 operation when initializing the spi, several options need to be specified. this is done by programming the appropriate control bits (sspcon<5:0> and sspstat<7:6>). these control bits allow the following to be specified: ? master mode (sck is the clock output) ? slave mode (sck is the clock input) ? clock polarity (idle state of sck) ? data input sample phase (middle or end of data output time) ? clock edge (output data on rising/falling edge of sck) ? clock rate (master mode only) ? slave select mode (slave mode only) the ssp consists of a transmit/receive shift register (sspsr) and a buffer register (sspbuf). the sspsr shifts the data in and out of the device, msb first. the sspbuf holds the data that was written to the sspsr until the received data is ready. once the eight bits of data have been received, that byte is moved to the sspbuf register. then, the buffer full detect bit, bf (sspstat<0>), and the interrupt flag bit, sspif, are set. this double-buffering of the received data (sspbuf) allows the next byte to start reception before reading the data that was just received. any write to the sspbuf register during transmission/reception of data will be ignored and the write collision detect bit, wcol (sspcon<7>), will be set. user software must clear the wcol bit so that it can be determined if the following write(s) to the sspbuf register completed successfully. when the application software is expecting to receive valid data, the sspbuf should be read before the next byte of data to transfer is written to the sspbuf. buffer full bit, bf (sspstat<0>), indicates when sspbuf has been loaded with the received data (transmission is complete). when the sspbuf is read, the bf bit is cleared. this data may be irrelevant if the spi is only a transmitter. generally, the ssp interrupt is used to determine when the transmission/reception has com- pleted. the sspbuf must be read and/or written. if the interrupt method is not going to be used, then software polling can be done to ensure that a write collision does not occur. example 14-1 shows the loading of the sspbuf (sspsr) for data transmission. the sspsr is not directly readable or writable and can only be accessed by addressing the sspbuf register. additionally, the ssp status register (sspstat) indicates the various status conditions. example 14-1: loading the sspbuf (sspsr) register loop btfss sspstat, bf ;has data been received(transmit complete)? bra loop ;no movf sspbuf, w ;wreg reg = contents of sspbuf movwf rxdata ;save in user ram, if data is meaningful movf txdata, w ;w reg = contents of txdata movwf sspbuf ;new data to xmit
PIC16F917/916/914/913 ds41250d-page 164 preliminary ? 2005 microchip technology inc. 14.3 enabling spi i/o to enable the serial port, ssp enable bit, sspen (sspcon<5>), must be set. to reset or reconfigure spi mode, clear the sspen bit, re-initialize the sspcon registers and then set the sspen bit. this configures the sdi, sdo, sck and ss pins as serial port pins. for the pins to behave as the serial port func- tion, some must have their data direction bits (in the tris register) appropriately programmed. that is: ? sdi is automatically controlled by the spi module ? sdo must have trisc<4> bit cleared ? sck (master mode) must have trisc<6> bit cleared ? sck (slave mode) must have trisc<6> bit set ?ss must have trisa<5> bit set any serial port function that is not desired may be overridden by programming the corresponding data direction (tris) register to the opposite value. 14.4 typical connection figure 14-2 shows a typical connection between two microcontrollers. the master controller (processor 1) initiates the data transfer by sending the sck signal. data is shifted out of both shift registers on their programmed clock edge and latched on the opposite edge of the clock. both processors should be programmed to the same clock polarity (ckp), then both controllers would send and receive data at the same time. whether the data is meaningful (or dummy data) depends on the application software. this leads to three scenarios for data transmission: ? master sends data ? slave sends dummy data ? master sends data ? slave sends data ? master sends dummy data ? slave sends data figure 14-2: spi? master/slave connection serial input buffer (sspbuf) shift register (sspsr) msb lsb sdo sdi processor 1 sck spi? master sspm<3:0> = 00xxb serial input buffer (sspbuf) shift register (sspsr) lsb msb sdi sdo processor 2 sck spi? slave sspm<3:0> = 010xb serial clock
? 2005 microchip technology inc. preliminary ds41250d-page 165 PIC16F917/916/914/913 14.5 master mode the master can initiate the data transfer at any time because it controls the sck. the master determines when the slave (processor 2, figure 14-2) is to broadcast data by the software protocol. in master mode, the data is transmitted/received as soon as the sspbuf register is written to. if the spi is only going to receive, the sdo output could be disabled (programmed as an input). the sspsr register will continue to shift in the signal present on the sdi pin at the programmed clock rate. as each byte is received, it will be loaded into the sspbuf register as if a normal received byte (interrupts and status bits appropriately set). this could be useful in receiver applications as a ?line activity monitor? mode. the clock polarity is selected by appropriately program- ming the ckp bit (sspcon<4>). this then, would give waveforms for spi communication as shown in figure 14-3, figure 14-5 and figure 14-6, where the msb is transmitted first. in master mode, the spi clock rate (bit rate) is user programmable to be one of the following: ?f osc /4 (or t cy ) ?f osc /16 (or 4 ? t cy ) ?f osc /64 (or 16 ? t cy ) ? timer2 output/2 this allows a maximum data rate (at 40 mhz) of 10 mbps. figure 14-3 shows the waveforms for master mode. when the cke bit is set, the sdo data is valid before there is a clock edge on sck. the change of the input sample is shown based on the state of the smp bit. the time when the sspbuf is loaded with the received data is shown. figure 14-3: spi? mode waveform (master mode) sck (ckp = 0 sck (ckp = 1 sck (ckp = 0 sck (ckp = 1 4 clock modes input sample input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 0 sdi sspif (smp = 1 ) (smp = 0 ) (smp = 1 ) cke = 1 ) cke = 0 ) cke = 1 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 (cke = 0 ) (cke = 1 ) next q4 cycle after q2
PIC16F917/916/914/913 ds41250d-page 166 preliminary ? 2005 microchip technology inc. 14.6 slave mode in slave mode, the data is transmitted and received as the external clock pulses appear on sck. when the last bit is latched, the sspif interrupt flag bit is set. while in slave mode, the external clock is supplied by the external clock source on the sck pin. this external clock must meet the minimum high and low times as specified in the electrical specifications. while in sleep mode, the slave can transmit/receive data. when a byte is received, the device will wake-up from sleep. 14.7 slave select synchronization the ss pin allows a synchronous slave mode. the spi must be in slave mode with ss pin control enabled (sspcon<3:0> = 04h). the pin must not be driven low for the ss pin to function as an input. the data latch must be high. when the ss pin is low, transmission and reception are enabled and the sdo pin is driven. when the ss pin goes high, the sdo pin is no longer driven, even if in the middle of a transmitted byte, and becomes a floating output. external pull-up/pull-down resistors may be desirable, depending on the applica- tion. when the spi module resets, the bit counter is forced to ? 0 ?. this can be done by either forcing the ss pin to a high level or clearing the sspen bit. to emulate two-wire communication, the sdo pin can be connected to the sdi pin. when the spi needs to operate as a receiver, the sdo pin can be configured as an input. this disables transmissions from the sdo. the sdi can always be left as an input (sdi function) since it cannot create a bus conflict. figure 14-4: slave synchronization waveform note 1: when the spi is in slave mode with ss pin control enabled (sspcon<3:0> = 0100 ), the spi module will reset if the ss pin is set to v dd . 2: if the spi is used in slave mode with cke set, then the ss pin control must be enabled. sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 sdo bit 7 bit 6 bit 7 sspif interrupt (smp = 0 ) cke = 0 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss flag bit 0 bit 7 bit 0 next q4 cycle after q2
? 2005 microchip technology inc. preliminary ds41250d-page 167 PIC16F917/916/914/913 figure 14-5: spi? mode waveform (slave mode with cke = 0 ) figure 14-6: spi? mode waveform (slave mode with cke = 1 ) sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspif interrupt (smp = 0 ) cke = 0 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss flag optional next q4 cycle after q2 sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspif interrupt (smp = 0 ) cke = 1 ) cke = 1 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss flag not optional next q4 cycle after q2
PIC16F917/916/914/913 ds41250d-page 168 preliminary ? 2005 microchip technology inc. 14.8 sleep operation in master mode, all module clocks are halted and the transmission/reception will remain in that state until the device wakes from sleep. after the device returns to normal mode, the module will continue to trans- mit/receive data. in slave mode, the spi transmit/receive shift register operates asynchronously to the device. this allows the device to be placed in sleep mode and data to be shifted into the spi transmit/receive shift register. when all 8 bits have been received, the ssp interrupt flag bit will be set and if enabled, will wake the device from sleep. 14.9 effects of a reset a reset disables the ssp module and terminates the current transfer. 14.10 bus mode compatibility table 14-1 shows the compatibility between the standard spi modes and the states of the ckp and cke control bits. table 14-1: spi? bus modes there is also a smp bit which controls when the data is sampled. table 14-2: registers associated with spi? operation standard spi? mode terminology control bits state ckp cke 0, 0 0 1 0, 1 0 0 1, 0 1 1 1, 1 1 0 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh,8bh. 10bh,18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 13h sspbuf synchronous serial port receive buffer/transmit register xxxx xxxx uuuu uuuu 14h sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 0000 0000 87h trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 1111 1111 1111 1111 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 94h sspstat smp cke d/a p s r/w ua bf 0000 0000 0000 0000 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by the ssp in spi mode.
? 2005 microchip technology inc. preliminary ds41250d-page 169 PIC16F917/916/914/913 14.11 ssp i 2 c operation the ssp module in i 2 c mode, fully implements all slave functions, except general call support, and pro- vides interrupts on start and stop bits in hardware to facilitate firmware implementations of the master func- tions. the ssp module implements the standard mode specifications, as well as 7-bit and 10-bit addressing. two pins are used for data transfer. these are the rc6/tx/ck/sck/scl/seg9 pin, which is the clock (scl), and the rc7/rx/dt/sdi/sda/seg8 pin, which is the data (sda). the ssp module functions are enabled by setting ssp enable bit sspen (sspcon<5>). figure 14-7: ssp block diagram (i 2 c? mode) the ssp module has five registers for the i 2 c operation, which are listed below. ? ssp control register (sspcon) ? ssp status register (sspstat) ? serial receive/transmit buffer (sspbuf) ? ssp shift register (sspsr) ? not directly accessible ? ssp address register (sspadd) the sspcon register allows control of the i 2 c operation. four mode selection bits (sspcon<3:0>) allow one of the following i 2 c modes to be selected: ?i 2 c slave mode (7-bit address) ?i 2 c slave mode (10-bit address) ?i 2 c slave mode (7-bit address), with start and stop bit interrupts enabled to support firmware master mode ?i 2 c slave mode (10-bit address), with start and stop bit interrupts enabled to support firmware master mode ?i 2 c start and stop bit interrupts enabled to support firmware master mode; slave is idle selection of any i 2 c mode with the sspen bit set forces the scl and sda pins to be open drain, pro- vided these pins are programmed to inputs by setting the appropriate trisc bits. pull-up resistors must be provided externally to the scl and sda pins for proper operation of the i 2 c module. additional information on ssp i 2 c o peration can be found in the ? picmicro ? mid-range mcu family reference manual ? (ds33023). 14.12 slave mode in slave mode, the scl and sda pins must be config- ured as inputs (trisc<7:6> set). the ssp module will override the input state with the output data when required (slave-transmitter). when an address is matched, or the data transfer after an address match is received, the hardware automati- cally will generate the acknowledge (ack ) pulse, and then load the sspbuf register with the received value currently in the sspsr register. there are certain conditions that will cause the ssp module not to give this ack pulse. they include (either or both): a) the buffer full bit bf (sspstat<0>) was set before the transfer was received. b) the overflow bit sspov (sspcon<6>) was set before the transfer was received. in this case, the sspsr register value is not loaded into the sspbuf, but bit sspif (pir1<3>) is set. table 14-3 shows the results of when a data transfer byte is received, given the status of bits bf and sspov. the shaded cells show the condition where user software did not properly clear the overflow condition. flag bit bf is cleared by reading the sspbuf register, while bit sspov is cleared through software. the scl clock input must have a minimum high and low for proper operation. for high and low times of the i 2 c specification, as well as the requirements of the ssp module, see section 19.0 ?electrical specifica- tions? . read write sspsr reg match detect sspadd reg start and stop bit detect sspbuf reg internal data bus addr match set, reset s, p bits (sspstat reg ) rc6/tx/ rc7/ shift clock msb rx/dt/ lsb sdi/ ck/sck/ scl/seg9 sda/ seg8
PIC16F917/916/914/913 ds41250d-page 170 preliminary ? 2005 microchip technology inc. 14.12.1 addressing once the ssp module has been enabled, it waits for a start condition to occur. following the start condition, the 8-bits are shifted into the sspsr register. all incoming bits are sampled with the rising edge of the clock (scl) line. the value of register sspsr<7:1> is compared to the value of the sspadd register. the address is compared on the falling edge of the eighth clock (scl) pulse. if the addresses match, and the bf and sspov bits are clear, the following events occur: a) the sspsr register value is loaded into the sspbuf register. b) the buffer full bit, bf is set. c) an ack pulse is generated. d) ssp interrupt flag bit, sspif (pir1<3>) is set (interrupt is generated if enabled) on the falling edge of the ninth scl pulse. in 10-bit address mode, two address bytes need to be received by the slave (figure 14-8). the five most significant bits (msbs) of the first address byte specify if this is a 10-bit address. bit r/w (sspstat<2>) must specify a write so the slave device will receive the second address byte. for a 10-bit address, the first byte would equal ? 1111 0 a9 a8 0 ?, where a9 and a8 are the two msbs of the address. the sequence of events for 10-bit address is as follows, with steps 7-9 for slave-transmitter: 1. receive first (high) byte of address (bits sspif, bf and bit ua (sspstat<1>) are set). 2. update the sspadd register with second (low) byte of address (clears bit ua and releases the scl line). 3. read the sspbuf register (clears bit bf) and clear flag bit sspif. 4. receive second (low) byte of address (bits sspif, bf and ua are set). 5. update the sspadd register with the first (high) byte of address; if match releases scl line, this will clear bit ua. 6. read the sspbuf register (clears bit bf) and clear flag bit sspif. 7. receive repeated start condition. 8. receive first (high) byte of address (bits sspif and bf are set). 9. read the sspbuf register (clears bit bf) and clear flag bit sspif. table 14-3: data transfer received byte actions status bits as data transfer is received sspsr sspbuf generate ack pulse set bit sspif (ssp interrupt occurs if enabled) bf sspov 00 yes yes yes 10 no no yes 11 no no yes 0 1 no no yes note: shaded cells show the conditions where the user software did not properly clear the overflow condition.
? 2005 microchip technology inc. preliminary ds41250d-page 171 PIC16F917/916/914/913 14.12.2 reception when the r/w bit of the address byte is clear and an address match occurs, the r/w bit of the sspstat register is cleared. the received address is loaded into the sspbuf register. when the address byte overflow condition exists, then no acknowledge (ack ) pulse is given. an overflow condition is defined as either bit bf (sspstat<0>) is set, or bit sspov (sspcon<6>) is set. this is an error condition due to the user?s firmware. an ssp interrupt is generated for each data transfer byte. flag bit sspif (pir1<3>) must be cleared in software. the sspstat register is used to determine the status of the byte. figure 14-8: i 2 c? waveforms for reception (7-bit address) p 9 8 7 6 5 d0 d1 d2 d3 d4 d5 d6 d7 s a7 a6 a5 a4 a3 a2 a1 sda scl 12 3 4 5 6 7 8 9 12 3 4 56 7 89 123 4 bus master terminates transfer bit sspov is set because the sspbuf register is still full. cleared in software sspbuf register is read ack receiving data receiving data d0 d1 d2 d3 d4 d5 d6 d7 ack r/w = 0 receiving address sspif (pir1<3>) bf (sspstat<0>) sspov (sspcon<6>) ack ack is not sent.
PIC16F917/916/914/913 ds41250d-page 172 preliminary ? 2005 microchip technology inc. figure 14-9: i 2 c? slave mode timing (reception, 10-bit address) sda scl sspif bf (sspstat<0>) s 123456789 123456789 12345 789 p 1 1 1 1 0 a9a8 a7 a6a5 a4a3a2a1 a0 d7 d6d5d4d3 d1d0 receive data byte ack r/w = 0 ack receive first byte of address cleared in software d2 6 (pir1<3>) cleared in software receive second byte of address cleared by hardware when sspadd is updated with low byte of address ua (sspstat<1>) clock is held low until update of sspadd has taken place ua is set indicating that the sspadd needs to be updated ua is set indicating that sspadd needs to be updated cleared by hardware when sspadd is updated with high byte of address sspbuf is written with contents of sspsr dummy read of sspbuf to clear bf flag ack ckp 12345 789 d7 d6 d5 d4 d3 d1 d0 receive data byte bus maste r terminates transfer d2 6 ack cleared in software cleared in software sspov (sspcon<6>) sspov is set because sspbuf is still full. ack is not sen t. (ckp does not reset to ? 0 ? when sen = 0 ) clock is held low until update of sspadd has taken place
? 2005 microchip technology inc. preliminary ds41250d-page 173 PIC16F917/916/914/913 14.12.3 transmission when the r/w bit of the incoming address byte is set and an address match occurs, the r/w bit of the sspstat register is set. the received address is loaded into the sspbuf register. the ack pulse will be sent on the ninth bit, and pin rc6/tx/ck/sck/scl/seg9 is held low. the transmit data must be loaded into the sspbuf register, which also loads the sspsr register. then, pin rc6/tx/ck/sck/scl/seg9 should be enabled by setting bit ckp (sspcon<4>). the master must mon- itor the scl pin prior to asserting another clock pulse. the slave devices may be holding off the master by stretching the clock. the eight data bits are shifted out on the falling edge of the scl input. this ensures that the sda signal is valid during the scl high time (figure 14-10). an ssp interrupt is generated for each data transfer byte. flag bit sspif must be cleared in software, and the sspstat register is used to determine the status of the byte. flag bit sspif is set on the falling edge of the ninth clock pulse. as a slave-transmitter, the ack pulse from the master receiver is latched on the rising edge of the ninth scl input pulse. if the sda line was high (not ack ), then the data transfer is complete. when the ack is latched by the slave, the slave logic is reset (resets sspstat register) and the slave then monitors for another occur- rence of the start bit. if the sda line was low (ack ), the transmit data must be loaded into the sspbuf register, which also loads the sspsr register. then pin rc6/tx/ck/sck/scl/seg9 should be enabled by setting bit ckp. figure 14-10: i 2 c? waveforms for transmission (7-bit address) sda scl sspif (pir1<3>) bf (sspstat<0>) ckp (sspcon<4>) a7 a6 a5 a4 a3 a2 a1 ack d7 d6 d5 d4 d3 d2 d1 d0 ack transmitting data r/w = 1 receiving address 123456789 123456789 p cleared in software sspbuf is written in software from ssp interrupt service routine set bit after writing to sspbuf s data in sampled scl held low while cpu responds to sspif (the sspbuf must be written to before the ckp bit can be set)
PIC16F917/916/914/913 ds41250d-page 174 preliminary ? 2005 microchip technology inc. figure 14-11: i 2 c? slave mode timing (transmission, 10-bit address) sda scl sspif bf (sspstat<0>) s 123456789 123456789 12345 789 p 1 1 1 1 0 a9a8 a7 a6a5a4a3a2a1 a0 1 1 1 1 0 a8 r/w = 1 ack ack r/w = 0 ack receive first byte of address cleared in software bus master terminates transfer a9 6 (pir1<3>) receive second byte of address cleared by hardware when sspadd is updated with low byte of address ua (sspstat<1>) clock is held low until update of sspadd has taken place ua is set indicating that the sspadd needs to be updated ua is set indicating that sspadd needs to be updated cleared by hardware when sspadd is updated with high byte of address sspbuf is written with contents of dummy read of sspbuf to clear bf flag receive first byte of address 12345 789 d7 d6 d5 d4 d3 d1 ack d2 6 transmitting data byte d0 dummy read of sspbuf to clear bf flag sr cleared in software write of sspbuf initiates transmit cleared in software completion of clears bf flag ckp (sspcon<4>) ckp is set in software ckp is automatically cleared in hardware clock is held low until update of sspadd has taken place data transmission clock is held low until ckp is set to ? 1 ? bf flag is clear third address sequence at the end of the holding scl low sspsr
? 2005 microchip technology inc. preliminary ds41250d-page 175 PIC16F917/916/914/913 14.13 master mode master mode of operation is supported in firmware using interrupt generation on the detection of the start and stop conditions. the stop (p) and start (s) bits are cleared from a reset or when the ssp module is dis- abled. the stop (p) and start (s) bits will toggle based on the start and stop conditions. control of the i 2 c bus may be taken when the p bit is set or the bus is idle and both the s and p bits are clear. in master mode, the scl and sda lines are manipu- lated by clearing the corresponding trisc<6:7> bit(s). the output level is always low, irrespective of the value(s) in portc<6:7>. so when transmitting data, a ? 1 ? data bit must have the trisc<7> bit set (input) and a ? 0 ? data bit must have the trisc<7> bit cleared (out- put). the same scenario is true for the scl line with the trisc<6> bit. pull-up resistors must be provided externally to the scl and sda pins for proper opera- tion of the i 2 c module. the following events will cause the ssp interrupt flag bit, sspif, to be set (ssp interrupt will occur if enabled): ? start condition ? stop condition ? data transfer byte transmitted/received master mode of operation can be done with either the slave mode idle (sspm<3:0> = 1011 ), or with the slave active. when both master and slave modes are enabled, the software needs to differentiate the source(s) of the interrupt. 14.14 multi-master mode in multi-master mode, the interrupt generation on the detection of the start and stop conditions, allows the determination of when the bus is free. the stop (p) and start (s) bits are cleared from a reset or when the ssp module is disabled. the stop (p) and start (s) bits will toggle based on the start and stop conditions. control of the i 2 c bus may be taken when bit p (sspstat<4>) is set, or the bus is idle and both the s and p bits clear. when the bus is busy, enabling the ssp interrupt will generate the interrupt when the stop condition occurs. in multi-master operation, the sda line must be moni- tored to see if the signal level is the expected output level. this check only needs to be done when a high level is output. if a high level is expected and a low level is present, the device needs to release the sda and scl lines (set trisc<6:7>). there are two stages where this arbitration can be lost, these are: ? address transfer ? data transfer when the slave logic is enabled, the slave continues to receive. if arbitration was lost during the address transfer stage, communication to the device may be in progress. if addressed, an ack pulse will be gener- ated. if arbitration was lost during the data transfer stage, the device will need to re-transfer the data at a later time. 14.14.1 clock synchronization and the ckp bit when the ckp bit is cleared, the scl output is forced to ? 0 ?; however, setting the ckp bit will not assert the scl output low until the scl output is already sampled low. therefore, the ckp bit will not assert the scl line until an external i 2 c master device has already asserted the scl line. the scl output will remain low until the ckp bit is set and all other devices on the i 2 c bus have deasserted scl. this ensures that a write to the ckp bit will not violate the minimum high time requirement for scl (see figure 14-12).
PIC16F917/916/914/913 ds41250d-page 176 preliminary ? 2005 microchip technology inc. figure 14-12: clock synchronization timing table 14-4: registers associated with i 2 c? operation address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 13h sspbuf synchronous serial port receive buffer/transmit register xxxx xxxx uuuu uuuu 14h sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 0000 0000 87h trisc portc data direction register 1111 1111 1111 1111 93h sspadd synchronous serial port (i 2 c? mode) address register 0000 0000 0000 0000 94h sspstat smp (1) cke (1) d/a psr/w ua bf 0000 0000 0000 0000 legend: x = unknown, u = unchanged, - = unimplemented locations read as ? 0 ?. shaded cells are not used by ssp module in i 2 c mode. note 1: maintain these bits clear in i 2 c mode. sda scl dx-1 dx wr q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 sspcon ckp master device deasserts clock master device asserts clock
? 2005 microchip technology inc. preliminary ds41250d-page 177 PIC16F917/916/914/913 15.0 capture/compare/pwm modules each capture/compare/pwm (ccp) module contains a 16-bit register which can operate as a: ? 16-bit capture register ? 16-bit compare register ? pwm master/slave duty cycle register both the ccp1 and ccp2 modules are identical in operation, with the exception being the operation of the special event trigger. table 15-1 and table 15-2 show the resources and interactions of the ccp module(s). in the following sections, the operation of a ccp module is described with respect to ccp1. ccp2 operates the same as ccp1, except where noted. ccp1 module: capture/compare/pwm register1 (ccpr1) is com- prised of two 8-bit registers: ccpr1l (low byte) and ccpr1h (high byte). the ccp1con register controls the operation of ccp1. the special event trigger is generated by a compare match and will reset timer1. ccp2 module: capture/compare/pwm register2 (ccpr2) is com- prised of two 8-bit registers: ccpr2l (low byte) and ccpr2h (high byte). the ccp2con register controls the operation of ccp2. the special event trigger is generated by a compare match and will reset timer1 and start an a/d conversion (if the a/d module is enabled). additional information on ccp modules is available in the ? picmicro ? mid-range mcu family reference manual ? (ds33023) and in application note an594, ?using the ccp modules? (ds00594). table 15-1: ccp mode ? timer resources required table 15-2: interaction of two ccp modules ccp mode timer resource capture timer1 compare timer1 pwm timer2 ccpx mode ccpy mode interaction capture capture same tmr1 time base capture compare the compare should be configured for the special event trigger, which clears tmr1 compare compare the compare(s) should be configured for the special event trigger, which clears tmr1 pwm pwm the pwms will have the same frequency and update rate (tmr2 interrupt) pwm capture none pwm compare none
PIC16F917/916/914/913 ds41250d-page 178 preliminary ? 2005 microchip technology inc. register 15-1: ccp1con ? ccp2con (1) register (address: 17h/1dh) u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ccpxx ccpxy ccpxm3 ccpxm2 ccpxm1 ccpxm0 bit 7 bit 0 bit 7-6 unimplemented: read as ? 0 ? bit 5-4 ccpxx:ccpxy : pwm least significant bits capture mode : unused compare mode: unused pwm mode: these bits are the two lsbs of the pwm duty cycle. the eight msbs are found in ccprxl. bit 3-0 ccpxm<3:0> : ccpx mode select bits 0000 = capture/compare/pwm disabled (resets ccpx module) 0100 = capture mode, every falling edge 0101 = capture mode, every rising edge 0110 = capture mode, every 4th rising edge 0111 = capture mode, every 16th rising edge 1000 = compare mode, set output on match (ccpxif bit is set) 1001 = compare mode, clear output on match (ccpxif bit is set) 1010 = compare mode, generate software interrupt on match (ccpxif bit is set, ccpx pin is unaffected) 1011 = compare mode, trigger special event (ccpxif bit is set, ccpx pin is unaffected); ccp1 resets tmr1; ccp2 resets tmr1 and starts an a/d conversion (if a/d module is enabled) 11xx =pwm mode note 1: ccp2con used for pic16f914/917 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. preliminary ds41250d-page 179 PIC16F917/916/914/913 15.1 capture mode in capture mode, ccpr1h:ccpr1l captures the 16-bit value of the tmr1 register when an event occurs on pin rc5/t1cki/ccp1/seg10. an event is defined as one of the following: ? every falling edge ? every rising edge ? every 4th rising edge ? every 16th rising edge the type of event is configured by control bits ccp1m<3:0> (ccpxcon<3:0>). when a capture is made, the interrupt request flag bit ccp1if (pir1<2>) is set. the interrupt flag must be cleared in software. if another capture occurs before the value in register ccpr1 is read, the old captured value is overwritten by the new value. 15.1.1 ccp pin configuration in capture mode, the rc5/t1cki/ccp1/seg10 pin should be configured as an input by setting the trisc<5> bit. figure 15-3: capture mode operation block diagram 15.1.2 timer1 mode selection timer1 must be running in timer mode, or synchro- nized counter mode, for the ccp module to use the capture feature. in asynchronous counter mode, the capture operation may not work. 15.1.3 software interrupt when the capture mode is changed, a false capture interrupt may be generated. the user should keep bit ccp1ie (pie1<2>) clear to avoid false interrupts and should clear the flag bit ccp1if, following any such change in operating mode. 15.1.4 ccp prescaler there are four prescaler settings, specified by bits ccp1m<3:0>. whenever the ccp module is turned off, or the ccp module is not in capture mode, the prescaler counter is cleared. any reset will clear the prescaler counter. switching from one capture prescaler to another may generate an interrupt. also, the prescaler counter will not be cleared, therefore, the first capture may be from a non-zero prescaler. example 15-1 shows the recom- mended method for switching between capture pre- scalers. this example also clears the prescaler counter and will not generate the ?false? interrupt. example 15-1: changing between capture prescalers note: if the rc5/t1cki/ccp1/seg10 pin is configured as an output, a write to the port can cause a capture condition. ccpr1h ccpr1l tmr1h tmr1l set flag bit ccp1if (pir1<2>) capture enable qs ccp1con<3:0> rc5/t1cki/ prescaler 1, 4, 16 and edge detect pin ccp1/seg10 clrf ccp1con ; turn ccp module off movlw new_capt_ps ; load the w reg with ; the new prescaler ; move value and ccp on movwf ccp1con ; load ccp1con with this ; value
PIC16F917/916/914/913 ds41250d-page 180 preliminary ? 2005 microchip technology inc. 15.2 compare mode in compare mode, the 16-bit ccpr1 register value is constantly compared against the tmr1 register pair value. when a match occurs, the rc5/t1cki/ccp1/seg10 pin is: ? driven high ?driven low ? remains unchanged the action on the pin is based on the value of control bits ccp1m<3:0> (ccp1con<3:0>). at the same time, interrupt flag bit ccp1if is set. figure 15-4: compare mode operation block diagram 15.2.1 ccp pin configuration the user must configure the rc5/t1cki/ccp1/seg10 pin as an output by clearing the trisc<5> bit. 15.2.2 timer1 mode selection timer1 must be running in timer mode, or synchro- nized counter mode, if the ccp module is using the compare feature. in asynchronous counter mode, the compare operation may not work. 15.2.3 software interrupt mode when generate software interrupt mode is chosen, the rc5/t1cki/ccp1/seg10 pin is not affected. the ccpif bit is set, causing a ccp interrupt (if enabled). 15.2.4 special event trigger in this mode, an internal hardware trigger is generated, which may be used to initiate an action. the special event trigger output of ccp1 resets the tmr1 register pair. this allows the ccpr1 register to effectively be a 16-bit programmable period register for timer1. the special event trigger output of ccp2 resets the tmr1 register pair and starts an a/d conversion (if the a/d module is enabled). 15.3 pwm mode (pwm) in pulse width modulation mode, the ccpx pin pro- duces up to a 10-bit resolution pwm output. since the rc5/t1cki/ccp1/seg10 pin is multiplexed with the portc data latch, the trisc<5> bit must be cleared to make the rc5/t1cki/ccp1/seg10 pin an output. figure 15-5 shows a simplified block diagram of the ccp module in pwm mode. for a step-by-step procedure on how to set up the ccp module for pwm operation, see section 15.3.3 ?setup for pwm operation? . note: clearing the ccp1con register will force the rc5/t1cki/ccp1/seg10 compare output latch to the default low level. this is not the portc i/o data latch. ccpr1h ccpr1l tmr1h tmr1l comparator qs r output logic special event trigger set flag bit ccp1if (pir1<2>) match rc5/t1cki/ trisc<5> ccp1con<3:0> mode select output enable pin special event trigger will: reset timer1, but not set interrupt flag bit tmr1if (pir1<0>), and set bit go/done (adcon0<2>). ccp1/seg10 note: the special event trigger from the ccp1 and ccp2 modules will not set interrupt flag bit tmr1if (pir1<0>). note: clearing the ccp1con register will force the ccp1 pwm output latch to the default low level. this is not the portc i/o data latch.
? 2005 microchip technology inc. preliminary ds41250d-page 181 PIC16F917/916/914/913 figure 15-5: simplified pwm block diagram a pwm output (figure 15-6) has a time base (period) and a time that the output stays high (duty cycle). the frequency of the pwm is the inverse of the period (1/period). figure 15-6: pwm output 15.3.1 pwm period the pwm period is specified by writing to the pr2 register. the pwm period can be calculated using the following formula: pwm frequency is defined as 1/[pwm period]. when tmr2 is equal to pr2, the following three events occur on the next increment cycle: ?tmr2 is cleared ? the rc5/t1cki/ccp1/seg10 pin is set (exception: if pwm duty cycle = 0%, the rc5/t1cki/ccp1/seg10 pin will not be set) ? the pwm duty cycle is latched from ccpr1l into ccpr1h 15.3.2 pwm duty cycle the pwm duty cycle is specified by writing to the ccpr1l register and to the ccp1con<5:4> bits. up to 10-bit resolution is available. the ccpr1l contains the eight msbs and the ccp1con<5:4> contains the two lsbs. this 10-bit value is represented by ccpr1l:ccp1con<5:4>. the following equation is used to calculate the pwm duty cycle in time: ccpr1l and ccp1con<5:4> can be written to at any time, but the duty cycle value is not latched into ccpr1h until after a match between pr2 and tmr2 occurs (i.e., the period is complete). in pwm mode, ccpr1h is a read-only register. the ccpr1h register and a 2-bit internal latch are used to double buffer the pwm duty cycle. this double buffering is essential for glitch-free pwm operation. when the ccpr1h and 2-bit latch match tmr2, con- catenated with an internal 2-bit q clock, or 2 bits of the tmr2 prescaler, the ccp1 pin is cleared. the maximum pwm resolution (bits) for a given pwm frequency is given by the formula: ccpr1l ccpr1h (slave) comparator tmr2 comparator pr2 (1) r q s duty cycle registers ccp1con<5:4> clear timer, ccp1 pin and latch d.c. trisc<5> rc5/t1cki/ note 1: the 8-bit timer is concatenated with 2-bit internal q clock, or 2 bits of the prescaler, to create 10-bit time base. ccp1/seg10 period duty cycle tmr2 = pr2 tmr2 = duty cycle tmr2 = pr2 pwm period = (pr2) + 1] ? 4 ? t osc ? (tmr2 prescale value) note: the timer2 postscaler (see section 7.0 ?timer2 module? ) is not used in the determination of the pwm frequency. the postscaler could be used to have a servo update rate at a different frequency than the pwm output. note: if the pwm duty cycle value is longer than the pwm period, the rc5/t1cki/ccp1/seg10 pin will not be cleared. pwm duty cycle = (ccpr1l:ccp1con<5:4> ) ? t osc ? (tmr2 prescale value) pwm resolution f osc f pwm tmr2 prescaler ------------------------------------------------------------- ?? ?? log 2 () log --------------------------------------------------------------------------- bits =
PIC16F917/916/914/913 ds41250d-page 182 preliminary ? 2005 microchip technology inc. 15.3.3 setup for pwm operation the following steps should be taken when configuring the ccp module for pwm operation: 1. set the pwm period by writing to the pr2 register. 2. set the pwm duty cycle by writing to the ccpr1l register and ccp1con<5:4> bits. 3. make the rc5/t1cki/ccp1/seg10 pin an output by clearing the trisc<5> bit. 4. set the tmr2 prescale value and enable timer2 by writing to t2con. 5. configure the ccp1 module for pwm operation. table 15-1: example pwm frequencies and resolutions at 20 mhz table 15-2: registers associated with capture, compare and timer1 pwm frequency 1.22 khz 4.88 khz 19.53 khz 78.12khz 156.3 khz 208.3 khz timer prescaler (1, 4, 16) 16 4 1 1 1 1 pr2 value 0xffh 0xffh 0xffh 0x3fh 0x1fh 0x17h maximum resolution (bits) 10 10 10 8 7 5.5 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh,8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 0dh pir2 osfif c2if c1if lcdif ? lvdif ? ccp2if 0000 -0-0 0000 -0-0 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 8dh pie2 osfie c2ie c1ie lcdie ? lvdie ? ccp2ie 0000 -0-0 0000 -0-0 87h trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 1111 1111 1111 1111 0eh tmr1l holding register for the least signi ficant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 0fh tmr1h holding register for the most sign ificant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 10h t1con t1ginv t1ge t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0000 0000 uuuu uuuu 15h ccpr1l capture/compare/pwm register1 (lsb) xxxx xxxx uuuu uuuu 16h ccpr1h capture/compare/pwm register1 (msb) xxxx xxxx uuuu uuuu 17h ccp1con ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 1bh ccpr2l capture/compare/pwm register 2 (lsb) xxxx xxxx uuuu uuuu 1ch ccpr2h capture/compare/pwm register 2 (msb) xxxx xxxx uuuu uuuu 1dh ccp2con ? ? ccp2x ccp2y ccp2m3 ccp2m2 ccp2m1 ccp2m0 --00 0000 --00 0000 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by capture and timer1.
? 2005 microchip technology inc. preliminary ds41250d-page 183 PIC16F917/916/914/913 table 15-3: registers associated with pwm and timer2 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh,8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 0dh pir2 osfif c2if c1if lcdif ? lvdif ?ccp2if 0000 -0-0 0000 -0-0 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 8dh pie2 osfie c2ie c1ie lcdie ? lvdie ?ccp2ie 0000 -0-0 0000 -0-0 87h trisc portc data direction register 1111 1111 1111 1111 11h tmr2 timer2 module register 0000 0000 0000 0000 92h pr2 timer2 module period register 1111 1111 1111 1111 12h t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 15h ccpr1l capture/compare/pwm register 1 (lsb) xxxx xxxx uuuu uuuu 16h ccpr1h capture/compare/pwm register 1 (msb) xxxx xxxx uuuu uuuu 17h ccp1con ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 1bh ccpr2l capture/compare/pwm register 2 (lsb) xxxx xxxx uuuu uuuu 1ch ccpr2h capture/compare/pwm register 2 (msb) xxxx xxxx uuuu uuuu 1dh ccp2con ? ? ccp2x ccp2y ccp2m3 ccp2m2 ccp2m1 ccp2m0 --00 0000 --00 0000 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by pwm and timer2.
PIC16F917/916/914/913 ds41250d-page 184 preliminary ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. preliminary ds41250d-page 185 PIC16F917/916/914/913 16.0 special features of the cpu the PIC16F917/916/914/913 has a host of features intended to maximize system reliability, minimize cost through elimination of external components, provide power saving features and offer code protection. these features are: ? reset - power-on reset (por) - power-up timer (pwrt) - oscillator start-up timer (ost) - brown-out reset (bor) ? interrupts ? watchdog timer (wdt) ? oscillator selection ? sleep ? code protection ? id locations ? in-circuit serial programming? the PIC16F917/916/914/913 has two timers that offer necessary delays on power-up. one is the oscillator start-up timer (ost), intended to keep the chip in reset until the crystal oscillator is stable. the other is the power-up timer (pwrt), which provides a fixed delay of 64 ms (nominal) on power-up only, designed to keep the part in reset while the power supply stabilizes. there is also circuitry to reset the device if a brown-out occurs, which can use the power-up timer to provide at least a 64 ms reset. with these three functions-on-chip, most applications need no external reset circuitry. the sleep mode is designed to offer a very low-current power-down mode. the user can wake-up from sleep through: ?external reset ? watchdog timer wake-up ? an interrupt several oscillator options are also made available to allow the part to fit the application. the intosc option saves system cost, while the lp crystal option saves power. a set of configuration bits are used to select various options (see register 16-1).
PIC16F917/916/914/913 ds41250d-page 186 preliminary ? 2005 microchip technology inc. 16.1 configuration bits the configuration bits can be programmed (read as ? 0 ?), or left unprogrammed (read as ? 1 ?) to select various device configurations as shown in register 16-1. these bits are mapped in program memory location 2007h. register 16-1: config ? configuration word (address : 2007h) note: address 2007h is beyond the user program memory space. it belongs to the special configuration memory space (2000h-3fffh), which can be accessed only during programming. see ?PIC16F917/916/914/913 memory programming specification? (ds41244) for more information. ?debug fcmen ieso boren1 boren0 cpd cp mclre pwrte wdte fosc2 fosc1 fosc0 bit 13 bit 0 bit 13 unimplemented: read as ? 1 ? bit 12 debug : in-circuit debugger mode bit 1 = in-circuit debugger disabled, rb6/icspclk/icdck/seg14 and rb7/icspdat/icddat/seg13 are general purpose i/o pins 0 = in-circuit debugger enabled, rb6/icspclk/icdck/seg14 and rb7/icspdat/icddat/seg13 are dedicated to the debugger bit 11 fcmen: fail-safe clock monitor enabled bit 1 = fail-safe clock monitor is enabled 0 = fail-safe clock monitor is disabled bit 10 ieso: internal external switchover bit 1 = internal external switchover mode is enabled 0 = internal external switchover mode is disabled bit 9-8 boren<1:0>: brown-out reset selection bits (1) 11 = bor enabled 10 = bor enabled during operation and disabled in sleep 01 = bor controlled by sboren bit (pcon<4>) 00 = bor disabled bit 7 cpd : data code protection bit (2) 1 = data memory code protection is disabled 0 = data memory code protection is enabled bit 6 cp : code protection bit (3) 1 = program memory code protection is disabled 0 = program memory code protection is enabled bit 5 mclre: rb3/mclr /v pp pin function select bit (4) 1 = rb3/mclr /v pp pin function is mcl r 0 = rb3/mclr /v pp pin function is digital input, mclr internally tied to v dd bit 4 pwrte : power-up timer enable bit 1 = pwrt disabled 0 = pwrt enabled bit 3 wdte: watchdog timer enable bit 1 = wdt enabled 0 = wdt disabled and can be enabled by swdten bit (wdtcon<0>) bit 2-0 fosc<2:0>: oscillator selection bits 111 = rc oscillator: clko function on ra6/osc2/clko/t1oso pin, rc on ra7/osc1/clki/t1osi 110 = rcio oscillator: i/o function on ra6/osc2/clko/t1oso pin, rc on ra7/osc1/clki/t1osi 101 = intosc oscillator: clko function on ra6/osc2 /clko/t1oso pin, i/o function on ra7/osc1/clki/t1osi 100 = intoscio oscillator: i/o function on ra6/os c2/clko/t1oso pin, i/o function on ra7/osc1/clki/t1osi 011 = ec: i/o function on ra6/osc2/clko/t1oso pin, clki on ra7/osc1/clki/t1osi 010 = hs oscillator: high-speed crystal/resonator on ra6/osc2/clko/t1oso and ra7/osc1/clki/t1osi 001 = xt oscillator: crystal/resonator on ra6/osc2/clko/t1oso and ra7/osc1/clki/t1osi 000 = lp oscillator: low-power crystal on ra 6/osc2/clko/t1oso and ra7/osc1/clki/t1osi note 1: enabling brown-out reset does not automatically enable power-up timer. 2: the entire data eeprom will be erased when the code protection is turned off. 3: the entire program memory will be erased when the code protection is turned off. 4: when mclr is asserted in intosc or rc mode, the internal clock oscillator is disabled. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. preliminary ds41250d-page 187 PIC16F917/916/914/913 16.2 reset the PIC16F917/916/914/913 differentiates between various kinds of reset: a) power-on reset (por) b) wdt reset during normal operation c) wdt reset during sleep d) mclr reset during normal operation e) mclr reset during sleep f) brown-out reset (bor) some registers are not affected in any reset condition; their status is unknown on por and unchanged in any other reset. most other registers are reset to a ?reset state? on: ? power-on reset ?mclr reset ?mclr reset during sleep ?wdt reset ? brown-out reset (bor) they are not affected by a wdt wake-up since this is viewed as the resumption of normal operation. to and pd bits are set or cleared differently in different reset situations, as indicated in table 16-2. these bits are used in software to determine the nature of the reset. see table 16-5 for a full description of reset states of all registers. a simplified block diagram of the on-chip reset circuit is shown in figure 16-1. the mclr reset path has a noise filter to detect and ignore small pulses. see section 19.0 ?electrical specifications? for pulse width specifications. figure 16-1: simplified block diagram of on-chip reset circuit s r q external reset mclr /v pp pin v dd osc1/ wdt module v dd rise detect ost/pwrt lfintosc wdt time-out power-on reset ost 10-bit ripple counter pwrt chip_reset 11-bit ripple counter reset enable ost enable pwrt sleep brown-out (1) reset sboren boren clki pin note 1: refer to the configuration word register (register 16-1).
PIC16F917/916/914/913 ds41250d-page 188 preliminary ? 2005 microchip technology inc. 16.3 power-on reset the on-chip por circuit holds the chip in reset until v dd has reached a high enough level for proper operation. to take advantage of the por, simply connect the mclr pin through a resistor to v dd . this will eliminate external rc components usually needed to create power-on reset. a maximum rise time for v dd is required. see section 19.0 ?electrical specifi- cations? for details. if the bor is enabled, the maxi- mum rise time specification does not apply. the bor circuitry will keep the device in reset until v dd reaches v bor (see section 16.3.3 ?brown-out reset (bor)? ). when the device starts normal operation (exits the reset condition), device operating parameters (i.e., voltage, frequency, temperature, etc.) must be met to ensure operation. if these conditions are not met, the device must be held in reset until the operating conditions are met. for additional information, refer to application note an607, ?power-up trouble shooting? (ds00607). 16.3.1 m clr PIC16F917/916/914/913 has a noise filter in the mclr reset path. the filter will detect and ignore small pulses. it should be noted that a wdt reset does not drive mclr pin low. the behavior of the esd protection on the mclr pin has been altered from early devices of this family. voltages applied to the pin that exceed its specification can result in both mclr resets and excessive current beyond the device specification during the esd event. for this reason, microchip recommends that the mclr pin no longer be tied directly to v dd . the use of an rc network, as shown in figure 16-2, is suggested. an internal mclr option is enabled by clearing the mclre bit in the configuration word register. when cleared, mclr is internally tied to v dd and an internal weak pull-up is enabled for the mclr pin. in-circuit serial programming is not affected by selecting the internal mclr option. figure 16-2: recommended mclr circuit 16.3.2 power-up timer (pwrt) the power-up timer provides a fixed 64 ms (nominal) time-out on power-up only, from por or brown-out reset. the power-up timer operates from the 31 khz lfintosc oscillator. for more information, see section 4.4 ?internal clock modes? . the chip is kept in reset as long as pwrt is active. the pwrt delay allows the v dd to rise to an acceptable level. a config- uration bit, pwrte , can disable (if set) or enable (if cleared or programmed) the power-up timer. the power-up timer should be enabled when brown-out reset is enabled, although it is not required. the power-up timer delay will vary from chip-to-chip and vary due to: ?v dd variation ? temperature variation ? process variation see dc parameters for details ( section 19.0 ?electrical specifications? ). note: the por circuit does not produce an internal reset when v dd declines. to re-enable the por, v dd must reach vss for a minimum of 100 s. v dd PIC16F917/916/ mclr r1 1k ( or greater) c1 0.1 f (optional, not critical) 914/913
? 2005 microchip technology inc. preliminary ds41250d-page 189 PIC16F917/916/914/913 16.3.3 brown-out reset (bor) the boren0 and boren1 bits in the configuration word register selects one of four bor modes. two modes have been added to allow software or hardware control of the bor enable. when boren<1:0> = 01 , the sboren bit (pcon<4>) enables/disables the bor allowing it to be controlled in software. by select- ing boren<1:0>, the bor is automatically disabled in sleep to conserve power and enabled on wake-up. in this mode, the sboren bit is disabled. see register 16-1 for the configuration word definition. if v dd falls below v bor for greater than parameter (t bor ) (see section 19.0 ?electrical specifica- tions? ), the brown-out situation will reset the device. this will occur regardless of v dd slew rate. a reset is not insured to occur if v dd falls below v bor for less than parameter (t bor ). on any reset (power-on, brown-out reset, watchdog timer, etc.), the chip will remain in reset until v dd rises above v bor (see figure 16-3). the power-up timer will now be invoked, if enabled and will keep the chip in reset an additional 64 ms. if v dd drops below v bor while the power-up timer is running, the chip will go back into a brown-out reset and the power-up timer will be re-initialized. once v dd rises above v bor , the power-up timer will execute a 64 ms reset. 16.3.4 bor calibration the PIC16F917/916/914/913 stores the bor calibra- tion values in fuses located in the calibration word (2008h). the calibration word is not erased when using the specified bulk erase sequence in the ?PIC16F917/916/914/913 memory programming specification? (ds41244) and thus, does not require reprogramming. figure 16-3: brown-out situations note: the power-up timer is enabled by the pwrte bit in the configuration word. address 2008h is beyond the user program memory space. it belongs to the special configuration memory space (2000h-3fffh), which can be accessed only during programming. see ?PIC16F917/916/914/913 memory programming specification? (ds41244) for more information. 64 ms (1) v bor v dd internal reset v bor v dd internal reset 64 ms (1) < 64 ms 64 ms (1) v bor v dd internal reset note 1: 64 ms delay only if pwrte bit is programmed to ? 0 ?.
PIC16F917/916/914/913 ds41250d-page 190 preliminary ? 2005 microchip technology inc. 16.3.5 time-out sequence on power-up, the time-out sequence is as follows: first, pwrt time-out is invoked after por has expired, then ost is activated after the pwrt time-out has expired. the total time-out will vary based on oscillator configu- ration and pwrte bit status. for example, in ec mode with pwrte bit erased (pwrt disabled), there will be no time-out at all. figure 16-4, figure 16-5 and figure 16-6 depict time-out sequences. the device can exe- cute code from the intosc while ost is active, by enabling two-speed start-up or fail-safe monitor (see section 4.6.2 ?two-speed start-up sequence? and section 4.7 ?fail-safe clock monitor? ). since the time-outs occur from the por pulse, if mclr is kept low long enough, the time-outs will expire. then, bringing mclr high will begin execution immediately (see figure 16-5). this is useful for testing purposes or to synchronize more than one PIC16F917/916/914/913 device operating in parallel. table 16-5 shows the reset conditions for some special registers, while table 16-5 shows the reset conditions for all the registers. 16.3.6 power control (pcon) register the power control (pcon) register (address 8eh) has two status bits to indicate what type of reset that last occurred. bit 0 is bor (brown-out reset). bor is unknown on power-on reset. it must then be set by the user and checked on subsequent resets to see if bor = 0 , indicating that a brown-out has occurred. the bor status bit is a ?don?t care? and is not necessarily predictable if the brown-out circuit is disabled (boren<1:0> = 00 in the configuration word register). bit 1 is por (power-on reset). it is a ? 0 ? on power-on reset and unaffected otherwise. the user must write a ? 1 ? to this bit following a power-on reset. on a subsequent reset, if por is ? 0 ?, it will indicate that a power-on reset has occurred (i.e., v dd may have gone too low). for more information, see section 16.3.3 ?brown-out reset (bor)? . table 16-1: time-out in various situations table 16-2: pcon bits and their significance table 16-3: summary of registers associated with brown-out oscillator configuration power-up brown-out reset wake-up from sleep pwrte = 0 pwrte = 1 pwrte = 0 pwrte = 1 xt, hs, lp (1) t pwrt + 1024 ? t osc 1024 ? t osc t pwrt + 1024 ? t osc 1024 ? t osc 1024 ? t osc rc, ec, intosc t pwrt ?t pwrt ?? note 1: lp mode with t1osc disabled. por bor to pd condition 0u11 power-on reset 1011 brown-out reset uu0u wdt reset uu00 wdt wake-up uuuu mclr reset during normal operation uu10 mclr reset during sleep legend: u = unchanged, x = unknown address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets (1) 03h status irp rp1 rpo to pd z dc c 0001 1xxx 000q quuu 8eh pcon ? ? ? sboren ? ?por bor --01 --qq --0u --uu legend: u = unchanged, x = unknown, - = unimplemented bit, reads as ? 0 ?, q = value depends on condition. shaded cells are not used by bor. note 1: other (non power-up) resets include mclr reset and watchdog timer reset during normal operation.
? 2005 microchip technology inc. preliminary ds41250d-page 191 PIC16F917/916/914/913 figure 16-4: time-out sequence on power-up (delayed mclr ): case 1 figure 16-5: time-out sequence on power-up (delayed mclr ): case 2 figure 16-6: time-out sequence on power-up (mclr with v dd ): case 3 t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset v dd mclr internal por pwrt time-out ost time-out internal reset t pwrt t ost t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset
PIC16F917/916/914/913 ds41250d-page 192 preliminary ? 2005 microchip technology inc. table 16-4: initialization condition for registers register address power-on reset ? mclr reset ? wdt reset ? brown-out reset (1) ? wake-up from sleep through interrupt ? wake-up from sleep through wdt time-out w? xxxx xxxx uuuu uuuu uuuu uuuu indf 00h/80h/ 100h/180h xxxx xxxx xxxx xxxx uuuu uuuu tmr0 01h/101h xxxx xxxx uuuu uuuu uuuu uuuu pcl 02h/82h/ 102h/182h 0000 0000 0000 0000 pc + 1 (3) status 03h/83h/ 103h/183h 0001 1xxx 000q quuu (4) uuuq quuu (4) fsr 04h/84h/ 104h/184h xxxx xxxx uuuu uuuu uuuu uuuu porta 05h xxxx xxxx 0000 0000 uuuu uuuu portb 06h/106h xxxx xxxx 0000 0000 uuuu uuuu portc 07h xxxx xxxx 0000 0000 uuuu uuuu portd 08h xxxx xxxx 0000 0000 uuuu uuuu porte 09h ---- xxxx ---- 0000 ---- uuuu pclath 0ah/8ah/ 10ah/18ah ---0 0000 ---0 0000 ---u uuuu intcon 0bh/8bh/ 10bh/18bh 0000 000x 0000 000x uuuu uuuu (2) pir1 0ch 0000 0000 0000 0000 uuuu uuuu (2) pir2 0dh 0000 -0-0 0000 -0-0 uuuu -u-u tmr1l 0eh xxxx xxxx uuuu uuuu uuuu uuuu tmr1h 0fh xxxx xxxx uuuu uuuu uuuu uuuu t1con 10h 0000 0000 uuuu uuuu uuuu uuuu tmr2 11h 01-0 0-00 01-0 0-00 uu-u u-uu t2con 12h -000 0000 -000 0000 -uuu uuuu sspbuf 13h xxxx xxxx xxxx xxxx uuuu uuuu sspcon 14h 0000 0000 0000 0000 uuuu uuuu ccpr1l 15h 0000 0000 0000 0000 uuuu uuuu ccpr1h 16h 0000 0010 0000 0010 uuuu uuuu ccp1con 17h 000x 000x 000x 000x uuuu uuuu rcsta 18h ---0 1000 ---0 1000 ---u uuuu txreg 19h 0000 0000 0000 0000 uuuu uuuu rcreg 1ah 0000 0000 0000 0000 uuuu uuuu ccp2con 1dh --00 0000 --00 0000 --uu uuuu adresh 1eh xxxx xxxx uuuu uuuu uuuu uuuu legend: u = unchanged, x = unknown, - = unimplemented bit, reads as ? 0 ?, q = value depends on condition. note 1: if v dd goes too low, power-on reset will be activated and registers will be affected differently. 2: one or more bits in intcon and/or pir1 will be affected (to cause wake-up). 3: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 4: see table 16-5 for reset value for specific condition. 5: if reset was due to brown-out, then bit 0 = 0 . all other resets will cause bit 0 = u .
? 2005 microchip technology inc. preliminary ds41250d-page 193 PIC16F917/916/914/913 adcon0 1fh 0000 0000 0000 0000 uuuu uuuu option_reg 81h/181h 1111 1111 1111 1111 uuuu uuuu trisa 85h 1111 1111 1111 1111 uuuu uuuu trisb 86h/186h 1111 1111 1111 1111 uuuu uuuu trisc 87h 1111 1111 1111 1111 uuuu uuuu trisd 88h 1111 1111 1111 1111 uuuu uuuu trise 89h 1111 1111 1111 1111 uuuu uuuu pie1 8ch 0000 0000 0000 0000 uuuu uuuu pie2 8dh 0000 0000 0000 0000 uuuu uuuu pcon 8eh --01 --0x --0u --uu (1,5) --uu --uu osccon 8fh -110 q000 -110 x000 -uuu uuuu osctune 90h ---0 0000 ---u uuuu ---u uuuu ansel 91h 1111 1111 1111 1111 uuuu uuuu pr2 92h 1111 1111 1111 1111 1111 1111 sspadd 93h 0000 0000 0000 0000 uuuu uuuu sspstat 94h 0000 0000 0000 0000 uuuu uuuu wpub 95h 1111 1111 1111 1111 uuuu uuuu iocb 96h 0000 ---- 0000 ---- uuuu ---- cmcon1 97h ---- --10 ---- --10 ---- --uu txsta 98h 0000 -010 0000 -010 uuuu -uuu spbrg 99h 0000 0000 0000 0000 uuuu uuuu cmcon0 9ch 0000 0000 0000 0000 uuuu uuuu vrcon 9dh 0-0- 0000 0-0- 0000 u-u- uuuu adresl 9eh xxxx xxxx uuuu uuuu uuuu uuuu adcon1 9fh -000 ---- -000 ---- -uuu ---- wdtcon 105h ---0 1000 ---0 1000 ---u uuuu lcdcon 107h 0001 0011 0001 0011 uuuu uuuu lcdps 108h 0000 0000 0000 0000 uuuu uuuu lvdcon 109h --00 -100 --00 -100 --uu -uuu eedatl 10ch 0000 0000 0000 0000 uuuu uuuu eeadrl 10dh 0000 0000 0000 0000 uuuu uuuu eedath 10eh --00 0000 0000 0000 uuuu uuuu eeadrh 10fh ---0 0000 0000 0000 uuuu uuuu lcddata0 110h xxxx xxxx uuuu uuuu uuuu uuuu lcddata1 111h xxxx xxxx uuuu uuuu uuuu uuuu lcddata2 112h xxxx xxxx uuuu uuuu uuuu uuuu legend: u = unchanged, x = unknown, - = unimplemented bit, reads as ? 0 ?, q = value depends on condition. note 1: if v dd goes too low, power-on reset will be activated and registers will be affected differently. 2: one or more bits in intcon and/or pir1 will be affected (to cause wake-up). 3: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 4: see table 16-5 for reset value for specific condition. 5: if reset was due to brown-out, then bit 0 = 0 . all other resets will cause bit 0 = u . table 16-4: initialization condition for registers (continued) register address power-on reset ? mclr reset ? wdt reset ? brown-out reset (1) ? wake-up from sleep through interrupt ? wake-up from sleep through wdt time-out
PIC16F917/916/914/913 ds41250d-page 194 preliminary ? 2005 microchip technology inc. table 16-5: initialization condition for special registers lcddata3 113h xxxx xxxx uuuu uuuu uuuu uuuu lcddata4 114h xxxx xxxx uuuu uuuu uuuu uuuu lcddata5 115h xxxx xxxx uuuu uuuu uuuu uuuu lcddata6 116h xxxx xxxx uuuu uuuu uuuu uuuu lcddata7 117h xxxx xxxx uuuu uuuu uuuu uuuu lcddata8 118h xxxx xxxx uuuu uuuu uuuu uuuu lcddata9 119h xxxx xxxx uuuu uuuu uuuu uuuu lcddata10 11ah xxxx xxxx uuuu uuuu uuuu uuuu lcddata11 11bh xxxx xxxx uuuu uuuu uuuu uuuu lcdse0 11ch 0000 0000 uuuu uuuu uuuu uuuu lcdse1 11dh 0000 0000 uuuu uuuu uuuu uuuu lcdse2 11eh 0000 0000 uuuu uuuu uuuu uuuu eecon1 18ch x--- x000 u--- q000 u--- uuuu legend: u = unchanged, x = unknown, - = unimplemented bit, reads as ? 0 ?, q = value depends on condition. note 1: if v dd goes too low, power-on reset will be activated and registers will be affected differently. 2: one or more bits in intcon and/or pir1 will be affected (to cause wake-up). 3: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 4: see table 16-5 for reset value for specific condition. 5: if reset was due to brown-out, then bit 0 = 0 . all other resets will cause bit 0 = u . table 16-4: initialization condition for registers (continued) register address power-on reset ? mclr reset ? wdt reset ? brown-out reset (1) ? wake-up from sleep through interrupt ? wake-up from sleep through wdt time-out condition program counter status register pcon register power-on reset 000h 0001 1xxx --01 --0x mclr reset during normal operation 000h 000u uuuu --0u --uu mclr reset during sleep 000h 0001 0uuu --0u --uu wdt reset 000h 0000 uuuu --0u --uu wdt wake-up pc + 1 uuu0 0uuu --uu --uu brown-out reset 000h 0001 1uuu --01 --10 interrupt wake-up from sleep pc + 1 (1) uuu1 0uuu --uu --uu legend: u = unchanged, x = unknown, - = unimplemented bit, reads as ? 0 ?. note 1: when the wake-up is due to an interrupt and global interrupt enable bit, gie, is set, the pc is loaded with the interrupt vector (0004h) after execution of pc + 1.
? 2005 microchip technology inc. preliminary ds41250d-page 195 PIC16F917/916/914/913 16.4 interrupts the PIC16F917/916/914/913 has multiple sources of interrupt: ? external interrupt rb0/int/seg0 ? tmr0 overflow interrupt ? portb change interrupts ? 2 comparator interrupts ? a/d interrupt ? timer1 overflow interrupt ? eeprom data write interrupt ? fail-safe clock monitor interrupt ? lcd interrupt ? plvd interrupt ? usart receive and transmit interrupts ? ccp1 and ccp2 interrupts ? tmr2 interrupt the interrupt control (intcon) register and peripheral interrupt request 1 (pir1) register record individual interrupt requests in flag bits. the intcon register also has individual and global interrupt enable bits. a global interrupt enable bit, gie (intcon<7>), enables (if set) all unmasked interrupts, or disables (if cleared) all interrupts. individual interrupts can be disabled through their corresponding enable bits in the intcon register and pie1 register. gie is cleared on reset. the return from interrupt instruction, retfie , exits the interrupt routine, as well as sets the gie bit, which re-enables unmasked interrupts. the following interrupt flags are contained in the intcon register: ? int pin interrupt ? portb change interrupt ? tmr0 overflow interrupt the peripheral interrupt flags are contained in the special registers, pir1 and pir2. the corresponding interrupt enable bit are contained in the special registers, pie1 and pie2. the following interrupt flags are contained in the pir1 register: ? eeprom data write interrupt ? a/d interrupt ? usart receive and transmit interrupts ? timer1 overflow interrupt ? ccp1 interrupt ? ssp interrupt the following interrupt flags are contained in the pir2 register: ? fail-safe clock monitor interrupt ? comparator 1 and 2 interrupts ? lcd interrupt ? plvd interrupt ? ccp2 interrupt when an interrupt is serviced: ? the gie is cleared to disable any further interrupt. ? the return address is pushed onto the stack. ? the pc is loaded with 0004h. for external interrupt events, such as the int pin or portb change interrupt, the interrupt latency will be three or four instruction cycles. the exact latency depends upon when the interrupt event occurs (see figure 16-8). the latency is the same for one or two-cycle instructions. once in the interrupt service routine, the source(s) of the interrupt can be determined by polling the interrupt flag bits. the interrupt flag bit(s) must be cleared in software before re-enabling interrupts to avoid multiple interrupt requests. for additional information on timer1, a/d or data eeprom modules, refer to the respective peripheral section. note 1: individual interrupt flag bits are set, regardless of the status of their corresponding mask bit or the gie bit. 2: when an instruction that clears the gie bit is executed, any interrupts that were pending for execution in the next cycle are ignored. the interrupts, which were ignored, are still pending to be serviced when the gie bit is set again. note: the ansel (91h) and cmcon0 (9ch) registers must be initialized to configure an analog channel as a digital input. pins configured as analog inputs will read ? 0 ?. also, if a lcd output function is active on an external interrupt pin, that interrupt function will be disabled.
PIC16F917/916/914/913 ds41250d-page 196 preliminary ? 2005 microchip technology inc. 16.4.1 rb0/int/seg0 interrupt external interrupt on rb0/int/seg0 pin is edge-trig- gered; either rising if the intedg bit (option<6>) is set, or falling, if the intedg bit is clear. when a valid edge appears on the rb0/int/seg0 pin, the intf bit (intcon<1>) is set. this interrupt can be disabled by clearing the inte control bit (intcon<4>). the intf bit must be cleared in software in the interrupt service routine before re-enabling this interrupt. the rb0/int/seg0 interrupt can wake-up the processor from sleep if the inte bit was set prior to going into sleep. the status of the gie bit decides whether or not the processor branches to the interrupt vector following wake-up (0004h). see section 16.7 ?power-down mode (sleep)? for details on sleep and figure 16-10 for timing of wake-up from sleep through rb0/int/seg0 interrupt. 16.4.2 tmr0 interrupt an overflow (ffh 00h) in the tmr0 register will set the t0if (intcon<2>) bit. the interrupt can be enabled/disabled by setting/clearing t0ie (intcon<5>) bit. see section 5.0 ?timer0 module? for operation of the timer0 module. 16.4.3 portb interrupt an input change on portb change sets the rbif (intcon<0>) bit. the interrupt can be enabled/disabled by setting/clearing the rbie (intcon<3>) bit. plus, individual pins can be config- ured through the iocb register. figure 16-7: interrupt logic note: if a change on the i/o pin should occur when the read operation is being executed (start of the q2 cycle), then the rbif interrupt flag may not get set. tmr1if tmr1ie c1if c1ie tmr0if tmr0ie intf inte rbif rbie gie peie wake-up (if in sleep mode) interrupt to cpu peif eeie eeif adif adie ioc-rb4 iocb4 ioc-rb5 iocb5 ioc-rb6 iocb6 ioc-rb7 iocb7 ccp2if ccp2ie osfif osfie c2if c2ie ccp1if ccp1ie * sspie sspif rcif rcie txif txie lcdif lcdie lvdif lvdie tmr2if tmr2ie * only available on the pic16f914/917.
? 2005 microchip technology inc. preliminary ds41250d-page 197 PIC16F917/916/914/913 figure 16-8: int pin interrupt timing table 16-6: summary of interrupt registers addr name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 0bh, 8bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x 0ch pir1 eeif adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 0dh pir2 osfif c2if c1if lcdif ?lvdif ? ccp2if 0000 -0-0 0000 -0-0 8ch pie1 eeie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 8dh pie2 osfie c2ie c1ie lcdie ?lvdie ? ccp2ie 0000 -0-0 0000 -0-0 legend: x = unknown, u = unchanged, - = unimplemented read as ? 0 ?, q = value depends upon condition. shaded cells are not used by the interrupt module. q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 osc1 clko (3) int pin intf flag (intcon<1>) gie bit (intcon<7>) instruction flow pc instruction fetched instruction executed interrupt latency pc pc + 1 pc + 1 0004h 0005h inst (0004h) inst (0005h) dummy cycle inst (pc) inst (pc + 1) inst (pc - 1) inst (0004h) dummy cycle inst (pc) ? note 1: intf flag is sampled here (every q1). 2: asynchronous interrupt latency = 3-4 t cy . synchronous latency = 3 t cy , where t cy = instruction cycle time. latency is the same whether inst (pc) is a single cycle or a 2-cycle instruction. 3: clko is available only in intosc and rc oscillator modes. 4: for minimum width of int pulse, refer to ac specifications in section 19.0 ?electrical specifications? . 5: intf is enabled to be set any time during the q4-q1 cycles. (1) (2) (4) (5) (1)
PIC16F917/916/914/913 ds41250d-page 198 preliminary ? 2005 microchip technology inc. 16.5 context saving during interrupts during an interrupt, only the return pc value is saved on the stack. typically, users may wish to save key registers during an interrupt (e.g., w and status registers). this must be implemented in software. since the lower 16 bytes of all banks are common in the PIC16F917/916/914/913 (see figure 2-3), temporary holding registers, w_temp and status_temp, should be placed in here. these 16 locations do not require banking and therefore, make it easier to context save and restore. the same code shown in example 16-1 can be used to: ? store the w register ? store the status register ? execute the isr code ? restore the status (and bank select bit register) ? restore the w register example 16-1: saving status and w registers in ram note: the PIC16F917/916/914/913 normally does not require saving the pclath. however, if computed goto ?s are used in the isr and the main code, the pclath must be saved and restored in the isr. movwf w_temp ;copy w to temp register swapf status,w ;swap status to be saved into w clrf status ;bank 0, regardless of current bank, clears irp,rp1,rp0 movwf status_temp ;save status to bank zero status_temp register : :(isr) ;insert user code here : swapf status_temp,w ;swap status_temp register into w ;(sets bank to original state) movwf status ;move w into status register swapf w_temp,f ;swap w_temp swapf w_temp,w ;swap w_temp into w
? 2005 microchip technology inc. preliminary ds41250d-page 199 PIC16F917/916/914/913 16.6 watchdog timer (wdt) for PIC16F917/916/914/913, the wdt has been mod- ified from previous pic16f devices. the new wdt is code and functionally compatible with previous pic16f wdt modules and adds a 16-bit prescaler to the wdt. this allows the user to have a scaled value for the wdt and tmr0 at the same time. in addition, the wdt time-out value can be extended to 268 seconds. wdt is cleared under certain conditions described in table 16-7. 16.6.1 wdt oscillator the wdt derives its time base from the 31 khz lfintosc. the lts bit does not reflect that the lfintosc is enabled. the value of wdtcon is ?---0 1000? on all resets. this gives a nominal time base of 16 ms, which is compatible with the time base generated with previous pic16f microcontroller versions. a new prescaler has been added to the path between the intosc and the multiplexers used to select the path for the wdt. this prescaler is 16 bits and can be programmed to divide the intosc by 32 to 65536, giving the wdt a nominal range of 1 ms to 268s. 16.6.2 wdt control the wdte bit is located in the configuration word register. when set, the wdt runs continuously. when the wdte bit in the configuration word register is set, the swdten bit (wdtcon<0>) has no effect. if wdte is clear, then the swdten bit can be used to enable and disable the wdt. setting the bit will enable it and clearing the bit will disable it. the psa and ps<2:0> bits (option_reg) have the same function as in previous versions of the pic16f family of microcontrollers. see section 5.0 ?timer0 module? for more information. figure 16-9: watchdog timer block diagram note: when the oscillator start-up timer (ost) is invoked, the wdt is held in reset, because the wdt ripple counter is used by the ost to perform the oscillator delay count. when the ost count has expired, the wdt will begin counting (if enabled). table 16-7: wdt status conditions wdt wdte = 0 cleared clrwdt command oscillator fail detected exit sleep + system clock = t1osc, extrc, intosc, extclk exit sleep + system clock = xt, hs, lp cleared until the end of ost 31 khz psa 16-bit wdt prescaler from tmr0 clock source prescaler (1) 8 ps<2:0> psa wdt time-out to t m r 0 wdtps<3:0> wdte from configuration word register 1 1 0 0 swdten from wdtcon lfintosc clock note 1 : this is the shared timer0/wdt prescaler. see section 5.4 ?prescaler? for more information.
PIC16F917/916/914/913 ds41250d-page 200 preliminary ? 2005 microchip technology inc. register 16-2: wdtcon ? watchdog timer control register (address: 105h) table 16-8: summary of watchdog timer registers u-0 u-0 u-0 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 ? ? ? wdtps3 wdtps2 wdtps1 wdtps0 swdten bit 7 bit 0 bit 7-5 unimplemented: read as ? 0 ? bit 4-1 wdtps<3:0>: watchdog timer period select bits bit value = prescale rate 0000 = 1:32 0001 = 1:64 0010 = 1:128 0011 = 1:256 0100 = 1:512 (reset value) 0101 = 1:1024 0110 = 1:2048 0111 = 1:4096 1000 = 1:8192 1001 = 1:16384 1010 = 1:32768 1011 = 1:65536 1100 = reserved 1101 = reserved 1110 = reserved 1111 = reserved bit 0 swdten: software enable or disable the watchdog timer bit (1) 1 = wdt is turned on 0 = wdt is turned off (reset value) note 1: if wdte configuration bit = 1 , then wdt is always enabled, irrespective of this control bit. if wdte configuration bit = 0 , then it is possible to turn wdt on/off with this control bit. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 105h wdtcon ? ? ? wdtps3 wdtps2 wstps1 wdtps0 swdten 81h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 2007h (1) config cpd cp mclre pwrte wdte fosc2 fosc1 fosc0 legend: shaded cells are not used by the watchdog timer. note 1: see register 16-1 for operation of all configuration word register bits.
? 2005 microchip technology inc. preliminary ds41250d-page 201 PIC16F917/916/914/913 16.7 power-down mode (sleep) the power-down mode is entered by executing a sleep instruction. if the watchdog timer is enabled: ? wdt will be cleared but keeps running. ?pd bit in the status register is cleared. ?to bit is set. ? oscillator driver is turned off. ? i/o ports maintain the status they had before sleep was executed (driving high, low or high-impedance). for lowest current consumption in this mode, all i/o pins should be either at v dd or v ss , with no external circuitry drawing current from the i/o pin, and the comparators and cv ref should be disabled. i/o pins that are high-impedance inputs should be pulled high or low externally to avoid switching currents caused by floating inputs. the t0cki input should also be at v dd or v ss for lowest current consumption. the contribution from on-chip pull-ups on portb should be considered. the mclr pin must be at a logic high level. 16.7.1 wake-up from sleep the device can wake-up from sleep through one of the following events: 1. external reset input on mclr pin. 2. watchdog timer wake-up (if wdt was enabled). 3. interrupt from rb0/int/seg0 pin, portb change or a peripheral interrupt. the first event will cause a device reset. the two latter events are considered a continuation of program execution. the to and pd bits in the status register can be used to determine the cause of device reset. the pd bit, which is set on power-up, is cleared when sleep is invoked. to bit is cleared if wdt wake-up occurred. the following peripheral interrupts can wake the device from sleep: 1. tmr1 interrupt. timer1 must be operating as an asynchronous counter. 2. eusart receive interrupt 3. a/d conversion (when a/d clock source is rc) 4. eeprom write operation completion 5. comparator output changes state 6. interrupt-on-change 7. external interrupt from int pin 8. plvd interrupt 9. lcd interrupt (if running during sleep) other peripherals cannot generate interrupts since during sleep, no on-chip clocks are present. when the sleep instruction is being executed, the next instruction (pc + 1) is pre-fetched. for the device to wake-up through an interrupt event, the corresponding interrupt enable bit must be set (enabled). wake-up is regardless of the state of the gie bit. if the gie bit is clear (disabled), the device continues execution at the instruction after the sleep instruction. if the gie bit is set (enabled), the device executes the instruction after the sleep instruction, then branches to the interrupt address (0004h). in cases where the execution of the instruction following sleep is not desirable, the user should have a nop after the sleep instruction. the wdt is cleared when the device wakes up from sleep, regardless of the source of wake-up. 16.7.2 wake-up using interrupts when global interrupts are disabled (gie cleared) and any interrupt source has both its interrupt enable bit and interrupt flag bit set, one of the following will occur: ? if the interrupt occurs before the execution of a sleep instruction, the sleep instruction will complete as a nop . therefore, the wdt and wdt prescaler and postscaler (if enabled) will not be cleared, the to bit will not be set and the pd bit will not be cleared. ? if the interrupt occurs during or after the execution of a sleep instruction, the device will immediately wake-up from sleep. the sleep instruction will be completely executed before the wake-up. therefore, the wdt and wdt prescaler and postscaler (if enabled) will be cleared, the to bit will be set and the pd bit will be cleared. note: it should be noted that a reset generated by a wdt time-out does not drive mclr pin low. note: if the global interrupts are disabled (gie is cleared), but any interrupt source has both its interrupt enable bit and the correspond- ing interrupt flag bits set, the device will immediately wake-up from sleep. the sleep instruction is completely executed.
PIC16F917/916/914/913 ds41250d-page 202 preliminary ? 2005 microchip technology inc. even if the flag bits were checked before executing a sleep instruction, it may be possible for flag bits to become set before the sleep instruction completes. to determine whether a sleep instruction executed, test the pd bit. if the pd bit is set, the sleep instruction was executed as a nop . to ensure that the wdt is cleared, a clrwdt instruction should be executed before a sleep instruction. figure 16-10: wake-up from sleep through interrupt q1 q2 q3 q4 q1 q2 q3 q4 q1 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 (1) clko (4) int pin intf flag (intcon<1>) gie bit (intcon<7>) instruction flow pc instruction fetched instruction executed pc pc + 1 pc + 2 inst(pc) = sleep inst(pc - 1) inst(pc + 1) sleep processor in sleep interrupt latency (3) inst(pc + 2) inst(pc + 1) inst(0004h) inst(0005h) inst(0004h) dummy cycle pc + 2 0004h 0005h dummy cycle t ost (2) pc + 2 note 1: xt, hs or lp oscillator mode assumed. 2: t ost = 1024 t osc (drawing not to scale). this delay does not apply to ec and rc oscillator modes. 3: gie = 1 assumed. in this case after wake-up, the processor jumps to 0004h. if gie = 0 , execution will continue in-line. 4: clko is not available in xt, hs, lp or ec oscillator modes, but shown here for timing reference.
? 2005 microchip technology inc. preliminary ds41250d-page 203 PIC16F917/916/914/913 16.8 code protection if the code protection bit(s) have not been programmed, the on-chip program memory can be read out using icsp for verification purposes. 16.9 id locations four memory locations (2000h-2003h) are designated as id locations where the user can store checksum or other code identification numbers. these locations are not accessible during normal execution, but are readable and writable during program/verify mode. only the least significant 7 bits of the id locations are used. 16.10 in-circuit serial programming the PIC16F917/916/914/913 microcontrollers can be serially programmed while in the end application circuit. this is simply done with two lines for clock and data and three other lines for: ? power ? ground ? programming voltage this allows customers to manufacture boards with unprogrammed devices and then program the micro- controller just before shipping the product. this also allows the most recent firmware or a custom firmware to be programmed. the device is placed into a program/verify mode by holding the rb7/icspdat/icddat/seg13 and rb6/icspclk/icdck/seg14 pins low, while raising the mclr (v pp ) pin from v il to v ihh . see ?PIC16F917/916/914/913 memory programming specification? (ds41244) for more information. rb7/icspdat/icddat/seg13 becomes the programming data and rb6/icspclk/icdck/seg14 becomes the programming clock. both rb7/icspdat/icddat/seg13 and rb6/icspclk/icdck/seg14 are schmitt trigger inputs in this mode. after reset, to place the device into program/verify mode, the program counter (pc) is at location 00h. a 6-bit command is then supplied to the device. depending on the command, 14 bits of program data are then supplied to or from the device, depending on whether the command was a load or a read. for complete details of serial programming, please refer to the ?PIC16F917/916/914/913 memory programming specification? (ds41244). a typical in-circuit serial programming connection is shown in figure 16-11. figure 16-11: typical in-circuit serial programming connection note: the entire data eeprom and flash program memory will be erased when the code protection is turned off. see the ?PIC16F917/916/914/913 memory pro- gramming specification? (ds41244) for more information. external connector signals to n o r m a l connections to n o rm a l connections PIC16F917/916/ v dd v ss re3/mclr /v pp rb6/icspclk/ rb7/icspdata/ +5v 0v v pp clk data i/o * * * * * isolation devices (as required) icdck/seg14 icddat/seg13 914/913
PIC16F917/916/914/913 ds41250d-page 204 preliminary ? 2005 microchip technology inc. 16.11 in-circuit debugger the PIC16F917/916/914/913-icd can be used in any of the package types. the device will be mounted on the target application board, which in turn has a 3 or 4 wire connection to the icd tool. when the debug bit in the configuration word (config<12>) is programmed to a ? 0 ?, the in-circuit debugger functionality is enabled. this function allows simple debugging functions when used with mplab ? icd 2. when the microcontroller has this feature enabled, some of the resources are not available for general use. see table 16-9 for more detail. for more information, see ?using mplab ? icd 2? (ds51265), available on microchip?s web site (www.microchip.com). 16.11.1 icd pinout the devices in the pic16f91x family carry the circuitry for the in-circuit debugger on-chip and on existing device pins. this eliminates the need for a separate die or package for the icd device. the pinout for the icd device is the same as the devices (see section 1.0 ?device overview? for complete pinout and pin descriptions). table 16-9 shows the location and function of the icd related pins on the 28 and 40 pin devices. table 16-9: PIC16F917/916/914/913-icd pin descriptions note: the user?s application must have the circuitry required to support icd functionality. once the icd circuitry is enabled, normal device pin functions on rb6/icspclk/icdck/seg14 and rb7/icspdat/icddat/seg13 will not be usable. the icd circuitry uses these pins for communication with the icd2 external debugger. pin (pdip) name type pull-up description pic16f914/917 pic16f913/916 40 28 icddata ttl ? in circuit debugger bidirectional data 39 27 icdclk st ? in circuit debugger bidirectional clock 11mclr /v pp hv ? programming voltage 11,32 20 v dd p? 12,31 8,19 v ss p? legend: ttl = ttl input buffer, st = schmitt trigger input buffer, p = power, hv = high voltage
? 2005 microchip technology inc. preliminary ds41250d-page 205 PIC16F917/916/914/913 17.0 instruction set summary the PIC16F917/916/914/913 instruction set is highly orthogonal and is comprised of three basic categories: ? byte-oriented operations ? bit-oriented operations ? literal and control operations each pic16 instruction is a 14-bit word divided into an opcode, which specifies the instruction type and one or more operands, which further specify the operation of the instruction. the formats for each of the categories is presented in figure 17-1, while the various opcode fields are summarized in table 17-1. table 17-2 lists the instructions recognized by the mpasm tm assembler. a complete description of each instruction is also available in the ? picmicro ? mid-range mcu family reference manual? (ds33023). for byte-oriented instructions, ? f ? represents a file register designator and ? d ? represents a destination designator. the file register designator specifies which file register is to be used by the instruction. the destination designator specifies where the result of the operation is to be placed. if ? d ? is zero, the result is placed in the w register. if ? d ? is one, the result is placed in the file register specified in the instruction. for bit-oriented instructions, ? b ? represents a bit field designator, which selects the bit affected by the operation, while ? f ? represents the address of the file in which the bit is located. for literal and control operations, ? k ? represents an 8-bit or 11-bit constant, or literal value. one instruction cycle consists of four oscillator periods; for an oscillator frequency of 4 mhz, this gives a normal instruction execution time of 1 s. all instructions are executed within a single instruction cycle, unless a conditional test is true, or the program counter is changed as a result of an instruction. when this occurs, the execution takes two instruction cycles, with the second cycle executed as a nop . all instruction examples use the format ? 0xhh ? to represent a hexadecimal number, where ? h ? signifies a hexadecimal digit. 17.1 read-modify-write operations any instruction that specifies a file register as part of the instruction performs a read-modify-write (r-m-w) operation. the register is read, the data is modified, and the result is stored according to either the instruc- tion, or the destination designator ? d ?. a read operation is performed on a register even if the instruction writes to that register. for example, a clrf gpio instruction will read gpio, clear all the data bits, then write the result back to gpio. this example would have the unintended result of clearing the condition that set the gpif flag. table 17-1: opcode field descriptions note: to maintain upward compatibility with future products, do not use the option and tris instructions. field description f register file address (0x00 to 0x7f) w working register (accumulator) b bit address within an 8-bit file register k literal field, constant data or label x don?t care location (= 0 or 1 ). the assembler will generate code with x = 0 . it is the recommended form of use for compatibility with all microchip software tools. d destination select; d = 0 : store result in w, d = 1 : store result in file register f. default is d = 1. pc program counter to time-out bit pd power-down bit
PIC16F917/916/914/913 ds41250d-page 206 preliminary ? 2005 microchip technology inc. figure 17-1: general format for instructions byte-oriented file register operations 13 8 7 6 0 d = 0 for destination w opcode d f (file #) d = 1 for destination f f = 7-bit file register address bit-oriented file register operations 13 10 9 7 6 0 opcode b (bit #) f (file #) b = 3-bit bit address f = 7-bit file register address literal and control operations 13 8 7 0 opcode k (literal) k = 8-bit immediate value 13 11 10 0 opcode k (literal) k = 11-bit immediate value general call and goto instructions only
? 2005 microchip technology inc. preliminary ds41250d-page 207 PIC16F917/916/914/913 table 17-2: PIC16F917/916/914/913 instruction set mnemonic, operands description cycles 14-bit opcode status affected notes msb lsb byte-oriented file register operations addwf andwf clrf clrw comf decf decfsz incf incfsz iorwf movf movwf nop rlf rrf subwf swapf xorwf f, d f, d f - f, d f, d f, d f, d f, d f, d f, d f - f, d f, d f, d f, d f, d add w and f and w with f clear f clear w complement f decrement f decrement f, skip if 0 increment f increment f, skip if 0 inclusive or w with f move f move w to f no operation rotate left f through carry rotate right f through carry subtract w from f swap nibbles in f exclusive or w with f 1 1 1 1 1 1 1 (2) 1 1 (2) 1 1 1 1 1 1 1 1 1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0111 0101 0001 0001 1001 0011 1011 1010 1111 0100 1000 0000 0000 1101 1100 0010 1110 0110 dfff dfff lfff 0xxx dfff dfff dfff dfff dfff dfff dfff lfff 0xx0 dfff dfff dfff dfff dfff ffff ffff ffff xxxx ffff ffff ffff ffff ffff ffff ffff ffff 0000 ffff ffff ffff ffff ffff c,dc,z z z z z z z z z c c c,dc,z z 1, 2 1, 2 2 1, 2 1, 2 1, 2, 3 1, 2 1, 2, 3 1, 2 1, 2 1, 2 1, 2 1, 2 1, 2 1, 2 bit-oriented file register operations bcf bsf btfsc btfss f, b f, b f, b f, b bit clear f bit set f bit test f, skip if clear bit test f, skip if set 1 1 1 (2) 1 (2) 01 01 01 01 00bb 01bb 10bb 11bb bfff bfff bfff bfff ffff ffff ffff ffff 1, 2 1, 2 3 3 literal and control operations addlw andlw call clrwdt goto iorlw movlw retfie retlw return sleep sublw xorlw k k k - k k k - k - - k k add literal and w and literal with w call subroutine clear watchdog timer go to address inclusive or literal with w move literal to w return from interrupt return with literal in w return from subroutine go into standby mode subtract w from literal exclusive or literal with w 1 1 2 1 2 1 1 2 2 2 1 1 1 11 11 10 00 10 11 11 00 11 00 00 11 11 111x 1001 0kkk 0000 1kkk 1000 00xx 0000 01xx 0000 0000 110x 1010 kkkk kkkk kkkk 0110 kkkk kkkk kkkk 0000 kkkk 0000 0110 kkkk kkkk kkkk kkkk kkkk 0100 kkkk kkkk kkkk 1001 kkkk 1000 0011 kkkk kkkk c,dc,z z to ,pd z to ,pd c,dc,z z note 1: when an i/o register is modified as a function of itself (e.g., movf gpio, 1 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tm r0 register (and where applicable, d = 1 ), the prescaler will be cleared if assigned to the timer0 module. 3: if program counter (pc) is modified, or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . note: additional information on the mid-range instruction set is available in the picmicro ? mid-range mcu family reference manual? (ds33023).
PIC16F917/916/914/913 ds41250d-page 208 preliminary ? 2005 microchip technology inc. 17.2 instruction descriptions addlw add literal and w syntax: [ label ] addlw k operands: 0 k 255 operation: (w) + k (w) status affected: c, dc, z description: the contents of the w register are added to the eight-bit literal ?k? and the result is placed in the w register. addwf add w and f syntax: [ label ] addwf f,d operands: 0 f 127 d [ 0,1 ] operation: (w) + (f) (destination) status affected: c, dc, z description: add the contents of the w register with register ?f?. if ?d? is ? 0 ?, the result is stored in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?. andlw and literal with w syntax: [ label ] andlw k operands: 0 k 255 operation: (w) .and. (k) (w) status affected: z description: the contents of w register are and?ed with the eight-bit literal ?k?. the result is placed in the w register. andwf and w with f syntax: [ label ] andwf f,d operands: 0 f 127 d [ 0,1 ] operation: (w) .and. (f) (destination) status affected: z description: and the w register with register ?f?. if ?d? is ? 0 ?, the result is stored in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?. bcf bit clear f syntax: [ label ] bcf f,b operands: 0 f 127 0 b 7 operation: 0 (f) status affected: none description: bit ?b? in register ?f? is cleared. bsf bit set f syntax: [ label ] bsf f,b operands: 0 f 127 0 b 7 operation: 1 (f) status affected: none description: bit ?b? in register ?f? is set. btfsc bit test, skip if clear syntax: [ label ] btfsc f,b operands: 0 f 127 0 b 7 operation: skip if (f) = 0 status affected: none description: if bit ?b? in register ?f? is ? 1 ?, the next instruction is executed. if bit ?b? in register ?f? is ? 0 ?, the next instruction is discarded, and a nop is executed instead, making this a two-cycle instruction.
? 2005 microchip technology inc. preliminary ds41250d-page 209 PIC16F917/916/914/913 btfss bit test f, skip if set syntax: [ label ] btfss f,b operands: 0 f 127 0 b < 7 operation: skip if (f) = 1 status affected: none description: if bit ?b? in register ?f? is ? 0 ?, the next instruction is executed. if bit ?b? is ? 1 ?, then the next instruction is discarded and a nop is executed instead, making this a two-cycle instruction. call call subroutine syntax: [ label ] call k operands: 0 k 2047 operation: (pc)+ 1 tos, k pc<10:0>, (pclath<4:3>) pc<12:11> status affected: none description: call subroutine. first, return address (pc + 1) is pushed onto the stack. the eleven-bit immediate address is loaded into pc bits <10:0>. the upper bits of the pc are loaded from pclath. call is a two-cycle instruction. clrf clear f syntax: [ label ] clrf f operands: 0 f 127 operation: 00h (f) 1 z status affected: z description: the contents of register ?f? are cleared and the z bit is set. clrw clear w syntax: [ label ] clrw operands: none operation: 00h (w) 1 z status affected: z description: w register is cleared. zero bit (z) is set. clrwdt clear watchdog timer syntax: [ label ] clrwdt operands: none operation: 00h wdt 0 wdt prescaler, 1 to 1 pd status affected: to , pd description: clrwdt instruction resets the watchdog timer. it also resets the prescaler of the wdt. status bits to and pd are set. comf complement f syntax: [ label ] comf f,d operands: 0 f 127 d [0,1] operation: (f ) (destination) status affected: z description: the contents of register ?f? are complemented. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f?. decf decrement f syntax: [ label ] decf f,d operands: 0 f 127 d [0,1] operation: (f) - 1 (destination) status affected: z description: decrement register ?f?. if ?d? is ? 0 ?, the result is stored in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?.
PIC16F917/916/914/913 ds41250d-page 210 preliminary ? 2005 microchip technology inc. decfsz decrement f, skip if 0 syntax: [ label ] decfsz f,d operands: 0 f 127 d [0,1] operation: (f) - 1 (destination); skip if result = 0 status affected: none description: the contents of register ?f? are decremented. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed back in register ?f?. if the result is ? 1 ?, the next instruction is executed. if the result is ? 0 ?, then a nop is executed instead, making it a two-cycle instruction. goto go to address syntax: [ label ] goto k operands: 0 k 2047 operation: k pc<10:0> pclath<4:3> pc<12:11> status affected: none description: goto is an unconditional branch. the eleven-bit immediate value is loaded into pc bits <10:0>. the upper bits of pc are loaded from pclath<4:3>. goto is a two-cycle instruction. incf increment f syntax: [ label ] incf f,d operands: 0 f 127 d [0,1] operation: (f) + 1 (destination) status affected: z description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed back in register ?f?. incfsz increment f, skip if 0 syntax: [ label ] incfsz f,d operands: 0 f 127 d [0,1] operation: (f) + 1 (destination), skip if result = 0 status affected: none description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed back in register ?f?. if the result is ? 1 ?, the next instruction is executed. if the result is ? 0 ?, a nop is executed instead, making it a two-cycle instruction. iorlw inclusive or literal with w syntax: [ label ] iorlw k operands: 0 k 255 operation: (w) .or. k (w) status affected: z description: the contents of the w register are or?ed with the eight-bit literal ?k?. the result is placed in the w register. iorwf inclusive or w with f syntax: [ label ] iorwf f,d operands: 0 f 127 d [0,1] operation: (w) .or. (f) (destination) status affected: z description: inclusive or the w register with register ?f?. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed back in register ?f?.
? 2005 microchip technology inc. preliminary ds41250d-page 211 PIC16F917/916/914/913 movf move f syntax: [ label ] movf f,d operands: 0 f 127 d [0,1] operation: (f) (dest) status affected: z encoding: 00 1000 dfff ffff description: the contents of register ?f? is moved to a destination dependent upon the status of ?d?. if ?d? = 0 , destination is w register. if ?d? = 1 , the destination is file register ?f? itself. ?d? = 1 is useful to test a file register since status flag z is affected. words: 1 cycles: 1 example : movf fsr, 0 after instruction w= value in fsr register z= 1 movlw move literal to w syntax: [ label ] movlw k operands: 0 k 255 operation: k (w) status affected: none encoding: 11 00xx kkkk kkkk description: the eight bit literal ?k? is loaded into w register. the ?don?t cares? will assemble as ? 0 ?s . words: 1 cycles: 1 example : movlw 0x5a after instruction w = 0x5a movwf move w to f syntax: [ label ] movwf f operands: 0 f 127 operation: (w) (f) status affected: none encoding: 00 0000 1fff ffff description: move data from w register to register ?f?. words: 1 cycles: 1 example : movwf option before instruction option = 0xff w = 0x4f after instruction option = 0x4f w = 0x4f nop no operation syntax: [ label ] nop operands: none operation: no operation status affected: none encoding: 00 0000 0xx0 0000 description: no operation. words: 1 cycles: 1 example : nop
PIC16F917/916/914/913 ds41250d-page 212 preliminary ? 2005 microchip technology inc. retfie return from interrupt syntax: [ label ] retfie operands: none operation: tos pc, 1 gie status affected: none encoding: 00 0000 0000 1001 description: return from interrupt. stack is poped and top-of-stack (tos) is loaded in the pc. interrupts are enabled by setting global interrupt enable bit, gie (intcon<7>). this is a two-cycle instruction. words: 1 cycles: 2 example : retfie after interrupt pc = tos gie = 1 retlw return with literal in w syntax: [ label ] retlw k operands: 0 k 255 operation: k (w); tos pc status affected: none encoding: 11 01xx kkkk kkkk description: the w register is loaded with the eight bit literal ?k?. the program counter is loaded from the top of the stack (the return address). this is a two-cycle instruction. words: 1 cycles: 2 example : table call table ; w contains table ;offset value ? ;w now has table value ? ? addwf pc ;w = offset retlw k1 ;begin table retlw k2 ; ? ? ? retlw kn ; end of table before instruction w = 0x07 after instruction w = value of k8 return return from subroutine syntax: [ label ] return operands: none operation: tos pc status affected: none description: return from subroutine. the stack is poped and the top of the stack (tos) is loaded into the program counter. this is a two-cycle instruction.
? 2005 microchip technology inc. preliminary ds41250d-page 213 PIC16F917/916/914/913 rlf rotate left f through carry syntax: [ label ] rlf f,d operands: 0 f 127 d [0,1] operation: see description below status affected: c encoding: 00 1101 dfff ffff description: the contents of register ?f? are rotated one bit to the left through the carry flag. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?. words: 1 cycles: 1 example : rlf reg1,0 before instruction reg1 = 1110 0110 c=0 after instruction reg1 = 1110 0110 w = 1100 1100 c=1 rrf rotate right f through carry syntax: [ label ] rrf f,d operands: 0 f 127 d [0,1] operation: see description below status affected: c description: the contents of register ?f? are rotated one bit to the right through the carry flag. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed back in register ?f?. register f c register f c sleep syntax: [ label ] sleep operands: none operation: 00h wdt, 0 wdt prescaler, 1 to , 0 pd status affected: to , pd description: the power-down status bit, pd is cleared. time-out status bit, to is set. watchdog timer and its prescaler are cleared. the processor is put into sleep mode with the oscillator stopped. sublw subtract w from literal syntax: [ label ] sublw k operands: 0 k 255 operation: k - (w) ( w) status affected: c, dc, z description: the w register is subtracted (2?s complement method) from the eight-bit literal ?k?. the result is placed in the w register. subwf subtract w from f syntax: [ label ] subwf f,d operands: 0 f 127 d [0,1] operation: (f) - (w) ( destination) status affected: c, dc, z description: subtract (2?s complement method) w register from register ?f?. if ?d? is ? 0 ?, the result is stored in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?.
PIC16F917/916/914/913 ds41250d-page 214 preliminary ? 2005 microchip technology inc. swapf swap nibbles in f syntax: [ label ] swapf f,d operands: 0 f 127 d [0,1] operation: (f<3:0>) (destination<7:4>), (f<7:4>) (destination<3:0>) status affected: none description: the upper and lower nibbles of register ?f? are exchanged. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed in register ?f?. xorlw exclusive or literal with w syntax: [ label ] xorlw k operands: 0 k 255 operation: (w) .xor. k ( w) status affected: z description: the contents of the w register are xor?ed with the eight-bit literal ?k?. the result is placed in the w register. xorwf exclusive or w with f syntax: [ label ] xorwf f,d operands: 0 f 127 d [0,1] operation: (w) .xor. (f) ( destination) status affected: z description: exclusive or the contents of the w register with register ?f?. if ?d? is ? 0 ?, the result is stored in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?.
? 2005 microchip technology inc. preliminary ds41250d-page 215 PIC16F917/916/914/913 18.0 development support the picmicro ? microcontrollers are supported with a full range of hardware and software development tools: ? integrated development environment - mplab ? ide software ? assemblers/compilers/linkers - mpasm tm assembler - mplab c17 and mplab c18 c compilers -mplink tm object linker/ mplib tm object librarian - mplab c30 c compiler - mplab asm30 assembler/linker/library ? simulators - mplab sim software simulator - mplab dspic30 software simulator ?emulators - mplab ice 2000 in-circuit emulator - mplab ice 4000 in-circuit emulator ? in-circuit debugger - mplab icd 2 ? device programmers -pro mate ? ii universal device programmer - picstart ? plus development programmer - mplab pm3 device programmer ? low-cost demonstration boards - picdem tm 1 demonstration board - picdem.net tm demonstration board - picdem 2 plus demonstration board - picdem 3 demonstration board - picdem 4 demonstration board - picdem 17 demonstration board - picdem 18r demonstration board - picdem lin demonstration board - picdem usb demonstration board ? evaluation kits -k ee l oq ? security ics - picdem msc -microid ? rfid -can - powersmart ? battery management -analog 18.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8/16-bit micro- controller market. the mplab ide is a windows ? based application that contains: ? an interface to debugging tools - simulator - programmer (sold separately) - emulator (sold separately) - in-circuit debugger (sold separately) ? a full-featured editor with color coded context ? a multiple project manager ? customizable data windows with direct edit of contents ? high-level source code debugging ? mouse over variable inspection ? extensive on-line help the mplab ide allows you to: ? edit your source files (either assembly or c) ? one touch assemble (or compile) and download to picmicro emulator and simulator tools (automatically updates all project information) ? debug using: - source files (assembly or c) - mixed assembly and c - machine code mplab ide supports multiple debugging tools in a single development paradigm, from the cost effective simulators, through low-cost in-circuit debuggers, to full-featured emulators. this eliminates the learning curve when upgrading to tools with increasing flexibility and power. 18.2 mpasm assembler the mpasm assembler is a full-featured, universal macro assembler for all picmicro mcus. the mpasm assembler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol ref- erence, absolute lst files that contain source lines and generated machine code and coff files for debugging. the mpasm assembler features include: ? integration into mplab ide projects ? user defined macros to streamline assembly code ? conditional assembly for multi-purpose source files ? directives that allow complete control over the assembly process
PIC16F917/916/914/913 ds41250d-page 216 preliminary ? 2005 microchip technology inc. 18.3 mplab c17 and mplab c18 c compilers the mplab c17 and mplab c18 code development systems are complete ansi c compilers for microchip?s pic17cxxx and pic18cxxx family of microcontrollers. these compilers provide powerful integration capabilities, superior code optimization and ease of use not found with other compilers. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. 18.4 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c17 and mplab c18 c compilers. it can link relocatable objects from precompiled libraries, using directives from a linker script. the mplib object librarian manages the creation and modification of library files of precompiled code. when a routine from a library is called from a source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the object linker/library features include: ? efficient linking of single libraries instead of many smaller files ? enhanced code maintainability by grouping related modules together ? flexible creation of libraries with easy module listing, replacement, deletion and extraction 18.5 mplab c30 c compiler the mplab c30 c compiler is a full-featured, ansi compliant, optimizing compiler that translates standard ansi c programs into dspic30f assembly language source. the compiler also supports many command line options and language extensions to take full advantage of the dspic30f device hardware capabili- ties and afford fine control of the compiler code generator. mplab c30 is distributed with a complete ansi c standard library. all library functions have been vali- dated and conform to the ansi c library standard. the library includes functions for string manipulation, dynamic memory allocation, data conversion, time- keeping and math functions (trigonometric, exponential and hyperbolic). the compiler provides symbolic information for high-level source debugging with the mplab ide. 18.6 mplab asm30 assembler, linker and librarian mplab asm30 assembler produces relocatable machine code from symbolic assembly language for dspic30f devices. mplab c30 compiler uses the assembler to produce it?s object file. the assembler generates relocatable object files that can then be archived or linked with other relocatable object files and archives to create an executable file. notable features of the assembler include: ? support for the entire dspic30f instruction set ? support for fixed-point and floating-point data ? command line interface ? rich directive set ? flexible macro language ? mplab ide compatibility 18.7 mplab sim software simulator the mplab sim software simulator allows code devel- opment in a pc hosted environment by simulating the picmicro series microcontrollers on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a file, or user defined key press, to any pin. the execu- tion can be performed in single-step, execute until break or trace mode. the mplab sim simulator fully supports symbolic debugging using the mplab c17 and mplab c18 c compilers, as well as the mpasm assembler. the software simulator offers the flexibility to develop and debug code outside of the laboratory environment, making it an excellent, economical software development tool. 18.8 mplab sim30 software simulator the mplab sim30 software simulator allows code development in a pc hosted environment by simulating the dspic30f series microcontrollers on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a file, or user defined key press, to any of the pins. the mplab sim30 simulator fully supports symbolic debugging using the mplab c30 c compiler and mplab asm30 assembler. the simulator runs in either a command line mode for automated tasks, or from mplab ide. this high-speed simulator is designed to debug, analyze and optimize time intensive dsp routines.
? 2005 microchip technology inc. preliminary ds41250d-page 217 PIC16F917/916/914/913 18.9 mplab ice 2000 high-performance universal in-circuit emulator the mplab ice 2000 universal in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for picmicro microcontrollers. software control of the mplab ice 2000 in-circuit emulator is advanced by the mplab integrated development environment, which allows editing, building, downloading and source debugging from a single environment. the mplab ice 2000 is a full-featured emulator system with enhanced trace, trigger and data monitor- ing features. interchangeable processor modules allow the system to be easily reconfigured for emulation of different processors. the universal architecture of the mplab ice in-circuit emulator allows expansion to support new picmicro microcontrollers. the mplab ice 2000 in-circuit emulator system has been designed as a real-time emulation system with advanced features that are typically found on more expensive development tools. the pc platform and microsoft ? windows 32-bit operating system were chosen to best make these features available in a simple, unified application. 18.10 mplab ice 4000 high-performance universal in-circuit emulator the mplab ice 4000 universal in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for high- end picmicro microcontrollers. software control of the mplab ice in-circuit emulator is provided by the mplab integrated development environment, which allows editing, building, downloading and source debugging from a single environment. the mplab icd 4000 is a premium emulator system, providing the features of mplab ice 2000, but with increased emulation memory and high-speed perfor- mance for dspic30f and pic18xxxx devices. its advanced emulator features include complex triggering and timing, up to 2 mb of emulation memory and the ability to view variables in real-time. the mplab ice 4000 in-circuit emulator system has been designed as a real-time emulation system with advanced features that are typically found on more expensive development tools. the pc platform and microsoft windows 32-bit operating system were chosen to best make these features available in a simple, unified application. 18.11 mplab icd 2 in-circuit debugger microchip?s in-circuit debugger, mplab icd 2, is a powerful, low-cost, run-time development tool, connecting to the host pc via an rs-232 or high-speed usb interface. this tool is based on the flash picmicro mcus and can be used to develop for these and other picmicro microcontrollers. the mplab icd 2 utilizes the in-circuit debugging capability built into the flash devices. this feature, along with microchip?s in-circuit serial programming tm (icsp tm ) protocol, offers cost effective in-circuit flash debugging from the graphical user interface of the mplab integrated development environment. this enables a designer to develop and debug source code by setting breakpoints, single-stepping and watching variables, cpu status and peripheral registers. running at full speed enables testing hardware and applications in real-time. mplab icd 2 also serves as a development programmer for selected picmicro devices. 18.12 pro mate ii universal device programmer the pro mate ii is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features an lcd display for instructions and error messages and a modular detachable socket assembly to support various package types. in stand-alone mode, the pro mate ii device programmer can read, verify and program picmicro devices without a pc connection. it can also set code protection in this mode. 18.13 mplab pm3 device programmer the mplab pm3 is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features a large lcd display (128 x 64) for menus and error messages and a modular detachable socket assembly to support various package types. the icsp? cable assembly is included as a standard item. in stand- alone mode, the mplab pm3 device programmer can read, verify and program picmicro devices without a pc connection. it can also set code protection in this mode. mplab pm3 connects to the host pc via an rs- 232 or usb cable. mplab pm3 has high-speed com- munications and optimized algorithms for quick pro- gramming of large memory devices and incorporates an sd/mmc card for file storage and secure data appli- cations.
PIC16F917/916/914/913 ds41250d-page 218 preliminary ? 2005 microchip technology inc. 18.14 picstart plus development programmer the picstart plus development programmer is an easy-to-use, low-cost, prototype programmer. it con- nects to the pc via a com (rs-232) port. mplab integrated development environment software makes using the programmer simple and efficient. the picstart plus development programmer supports most picmicro devices up to 40 pins. larger pin count devices, such as the pic16c92x and pic17c76x, may be supported with an adapter socket. the picstart plus development programmer is ce compliant. 18.15 picdem 1 picmicro demonstration board the picdem 1 demonstration board demonstrates the capabilities of the pic16c5x (pic16c54 to pic16c58a), pic16c61, pic16c62x, pic16c71, pic16c8x, pic17c42, pic17c43 and pic17c44. all necessary hardware and software is included to run basic demo programs. the sample microcontrollers provided with the picdem 1 demonstration board can be programmed with a pro mate ii device program- mer or a picstart plus development programmer. the picdem 1 demonstration board can be connected to the mplab ice in-circuit emulator for testing. a prototype area extends the circuitry for additional appli- cation components. features include an rs-232 interface, a potentiometer for simulated analog input, push button switches and eight leds. 18.16 picdem.net internet/ethernet demonstration board the picdem.net demonstration board is an internet/ ethernet demonstration board using the pic18f452 microcontroller and tcp/ip firmware. the board supports any 40-pin dip device that conforms to the standard pinout used by the pic16f877 or pic18c452. this kit features a user friendly tcp/ip stack, web server with html, a 24l256 serial eeprom for xmodem download to web pages into serial eeprom, icsp/mplab icd 2 interface con- nector, an ethernet interface, rs-232 interface and a 16 x 2 lcd display. also included is the book and cd-rom ?tcp/ip lean, web servers for embedded systems,? by jeremy bentham 18.17 picdem 2 plus demonstration board the picdem 2 plus demonstration board supports many 18, 28 and 40-pin microcontrollers, including pic16f87x and pic18fxx2 devices. all the neces- sary hardware and software is included to run the dem- onstration programs. the sample microcontrollers provided with the picdem 2 demonstration board can be programmed with a pro mate ii device program- mer, picstart plus development programmer, or mplab icd 2 with a universal programmer adapter. the mplab icd 2 and mplab ice in-circuit emulators may also be used with the picdem 2 demonstration board to test firmware. a prototype area extends the circuitry for additional application components. some of the features include an rs-232 interface, a 2 x 16 lcd display, a piezo speaker, an on-board temperature sensor, four leds and sample pic18f452 and pic16f877 flash microcontrollers. 18.18 picdem 3 pic16c92x demonstration board the picdem 3 demonstration board supports the pic16c923 and pic16c924 in the plcc package. all the necessary hardware and software is included to run the demonstration programs. 18.19 picdem 4 8/14/18-pin demonstration board the picdem 4 can be used to demonstrate the capa- bilities of the 8, 14 and 18-pin pic16xxxx and pic18xxxx mcus, including the pic16f818/819, pic16f87/88, pic16f62xa and the pic18f1320 family of microcontrollers. picdem 4 is intended to showcase the many features of these low pin count parts, including lin and motor control using eccp. special provisions are made for low-power operation with the supercapacitor circuit and jumpers allow on- board hardware to be disabled to eliminate current draw in this mode. included on the demo board are pro- visions for crystal, rc or canned oscillator modes, a five volt regulator for use with a nine volt wall adapter or battery, db-9 rs-232 interface, icd connector for programming via icsp and development with mplab icd 2, 2 x 16 liquid crystal display, pcb footprints for h- bridge motor driver, lin transceiver and eeprom. also included are: header for expansion, eight leds, four potentiometers, three push buttons and a proto- typing area. included with the kit is a pic16f627a and a pic18f1320. tutorial firmware is included along with the user?s guide.
? 2005 microchip technology inc. preliminary ds41250d-page 219 PIC16F917/916/914/913 18.20 picdem 17 demonstration board the picdem 17 demonstration board is an evaluation board that demonstrates the capabilities of several microchip microcontrollers, including pic17c752, pic17c756a, pic17c762 and pic17c766. a pro- grammed sample is included. the pro mate ii device programmer, or the picstart plus development pro- grammer, can be used to reprogram the device for user tailored application development. the picdem 17 demonstration board supports program download and execution from external on-board flash memory. a generous prototype area is available for user hardware expansion. 18.21 picdem 18r pic18c601/801 demonstration board the picdem 18r demonstration board serves to assist development of the pic18c601/801 family of microchip microcontrollers. it provides hardware implementation of both 8-bit multiplexed/demultiplexed and 16-bit memory modes. the board includes 2 mb external flash memory and 128 kb sram memory, as well as serial eeprom, allowing access to the wide range of memory types supported by the pic18c601/801. 18.22 picdem lin pic16c43x demonstration board the powerful lin hardware and software kit includes a series of boards and three picmicro microcontrollers. the small footprint pic16c432 and pic16c433 are used as slaves in the lin communication and feature on-board lin transceivers. a pic16f874 flash microcontroller serves as the master. all three micro- controllers are programmed with firmware to provide lin bus communication. 18.23 pickit tm 1 flash starter kit a complete ?development system in a box?, the pickit flash starter kit includes a convenient multi-section board for programming, evaluation and development of 8/14-pin flash pic ? microcontrollers. powered via usb, the board operates under a simple windows gui. the pickit 1 starter kit includes the user?s guide (on cd rom), pickit 1 tutorial software and code for various applications. also included are mplab ? ide (integrated development environment) software, software and hardware ?tips ?n tricks for 8-pin flash pic ? microcontrollers? handbook and a usb interface cable. supports all current 8/14-pin flash pic microcontrollers, as well as many future planned devices. 18.24 picdem usb pic16c7x5 demonstration board the picdem usb demonstration board shows off the capabilities of the pic16c745 and pic16c765 usb microcontrollers. this board provides the basis for future usb products. 18.25 evaluation and programming tools in addition to the picdem series of circuits, microchip has a line of evaluation kits and demonstration software for these products. ?k ee l oq evaluation and programming tools for microchip?s hcs secure data products ? can developers kit for automotive network applications ? analog design boards and filter design software ? powersmart battery charging evaluation/ calibration kits ?irda ? development kit ? microid development and rflab tm development software ? seeval ? designer kit for memory evaluation and endurance calculations ? picdem msc demo boards for switching mode power supply, high-power ir driver, delta sigma adc and flow rate sensor check the microchip web page and the latest product selector guide for the complete list of demonstration and evaluation kits.
PIC16F917/916/914/913 ds41250d-page 220 preliminary ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. advance information ds41250d-page 221 PIC16F917/916/914/913 19.0 electrical specifications absolute maximum ratings (?) ambient temperature under bias................................................................................................. .........-40 to +125c storage temperature ............................................................................................................ ............ -65c to +150c voltage on v dd with respect to v ss ................................................................................................... -0.3v to +6.5v voltage on mclr with respect to vss ............................................................................................... -0.3v to +1 3.5v voltage on all other pins with respect to v ss ........................................................................... -0.3v to (v dd + 0.3v) total power dissipation (1) ............................................................................................................................... 800 mw maximum current out of v ss pin ..................................................................................................................... 300 ma maximum current into v dd pin ........................................................................................................................ 250 ma input clamp current, i ik (v i < 0 or v i > v dd ) ................................................................................................................ 20 ma output clamp current, i ok (vo < 0 or vo >v dd ) .......................................................................................................... 20 ma maximum output current sunk by any i/o pin..................................................................................... ............... 25 ma maximum output current sourced by any i/o pin .................................................................................. ............ 25 ma maximum current sourced by all ports (combined) ................................................................................ ......... 200 ma maximum current sunk by by all ports (combined)................................................................................ .......... 200 ma note 1: power dissipation is calculated as follows: p dis = v dd x {i dd ? i oh } + {(v dd ? v oh ) x i oh } + (v ol x i ol ). 2: portd and porte are not implemented in pic16f913/916 devices. ? notice: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability. note: voltage spikes below v ss at the mclr pin, inducing currents greater than 80 ma, may cause latch-up. thus, a series resistor of 50-100 should be used when applying a ?low? level to the mclr pin, rather than pulling this pin directly to v ss .
PIC16F917/916/914/913 ds41250d-page 222 advance information ? 2005 microchip technology inc. figure 19-1: PIC16F917/916/914/913 voltage-frequency graph, -40c t a +125c 5.5 2.0 3.5 2.5 0 3.0 4.0 4.5 5.0 4 frequency (mhz) v dd (volts) note 1: the shaded region indicates the permissible combinations of voltage and frequency. 816 12 20 10
? 2005 microchip technology inc. advance information ds41250d-page 223 PIC16F917/916/914/913 19.1 dc characteristics: PIC16F917/916/914/913-i (industrial) PIC16F917/916/914/913-e (extended) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. sym characteristic min typ? max units conditions d001 d001c d001d v dd supply voltage 2.0 3.0 4.5 ? ? ? 5.5 5.5 5.5 v v v f osc < = 4 mhz: f osc < = 10 mhz f osc < = 20 mhz d002 v dr ram data retention voltage (1) 1.5* ? ? v device in sleep mode d003 v por v dd start voltage to ensure internal power-on reset signal ?v ss ?vsee section 16.3 ?power-on reset? for details. d004 s vdd v dd rise rate to ensure internal power-on reset signal 0.05 * ? ? v/ms see section 16.3 ?power-on reset? for details. d005 v bor brown-out reset ?2.1? v * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: this is the limit to which v dd can be lowered in sleep mode without losing ram data.
PIC16F917/916/914/913 ds41250d-page 224 advance information ? 2005 microchip technology inc. 19.2 dc characteristics: PIC16F917/916/914/913-i (industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device characteristics min typ? max units conditions v dd note d010 supply current (i dd ) (1, 2) ?8tbd a2.0f osc = 32 khz lp oscillator mode ?11tbd a3.0 ?33tbd a5.0 d011 ? 110 tbd a2.0f osc = 1 mhz xt oscillator mode ?190tbd a3.0 ?330tbd a5.0 d012 ? 220 tbd a2.0f osc = 4 mhz xt oscillator mode ?370tbd a3.0 ? 0.6 tbd ma 5.0 d013 ? 70 tbd a2.0f osc = 1 mhz ec oscillator mode ?140tbd a3.0 ?260tbd a5.0 d014 ? 180 tbd a2.0f osc = 4 mhz ec oscillator mode ?320tbd a3.0 ?500tbd a5.0 d015 ? 5 tbd a2.0f osc = 31 khz intosc mode ?14tbd a3.0 ?30tbdma5.0 d016 ? 340 tbd a2.0f osc = 4 mhz intosc mode ?500tbd a3.0 ? 0.8 tbd ma 5.0 d017 ? 180 tbd a2.0f osc = 4 mhz extrc mode ?320tbd a3.0 ?580tbd a5.0 d018 ? 2.1 tbd ma 4.5 f osc = 20 mhz hs oscillator mode ? 3.0 tbd ma 5.0 legend: tbd = to be determined ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt disabled. 2: the supply current is mainly a function of the operating voltage and frequency. other factors, such as i/o pin loading and switching rate, oscillator type, internal code execution pattern and temperature, also have an impact on the current consumption. 3: the peripheral current is the sum of the base i dd or i pd and the additional current consumed when this peripheral is enabled. the peripheral current can be determined by subtracting the base i dd or i pd current from this limit. max values should be used when calculating total current consumption. 4: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd .
? 2005 microchip technology inc. advance information ds41250d-page 225 PIC16F917/916/914/913 d020 power-down base current (i pd ) (4) ?0.1tbd a 2.0 wdt, bor, comparators, v ref and t1osc disabled ?0.5tbd a3.0 ?0.75tbd a5.0 d021 ? 0.6 tbd a 2.0 wdt current ?1.8tbd a3.0 ?8.4tbd a5.0 d022 ? 58 tbd a 3.0 bor current ?75tbd a5.0 d023 ? 35 tbd a 2.0 comparator current (3) ?65tbd a3.0 ?130tbd a5.0 d024 ? 40 tbd a2.0cv ref current ? 50.5 tbd a3.0 ?80tbd a5.0 d025 ? 2.1 tbd a 2.0 t1osc current ?2.5tbd a3.0 ?3.4tbd a5.0 d026 ? 1.2 tbd na 3.0 a/d current ?0.0022tbd a5.0 19.2 dc characteristics: PIC16F917/916/914/913-i (industrial) (continued) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device characteristics min typ? max units conditions v dd note legend: tbd = to be determined ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt disabled. 2: the supply current is mainly a function of the operating voltage and frequency. other factors, such as i/o pin loading and switching rate, oscillator type, internal code execution pattern and temperature, also have an impact on the current consumption. 3: the peripheral current is the sum of the base i dd or i pd and the additional current consumed when this peripheral is enabled. the peripheral current can be determined by subtracting the base i dd or i pd current from this limit. max values should be used when calculating total current consumption. 4: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd .
PIC16F917/916/914/913 ds41250d-page 226 advance information ? 2005 microchip technology inc. 19.3 dc characteristics: PIC16F917/916/914/913-e (extended) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40 c t a +125 c for extended param no. device characteristics min typ? max units conditions v dd note d010e supply current (i dd ) (1, 2) ?8tbd a2.0f osc = 32 khz lp oscillator mode ? 11 tbd a3.0 ?33tbd a5.0 d011e ? 110 tbd a2.0f osc = 1 mhz xt oscillator mode ? 190 tbd a3.0 ? 330 tbd a5.0 d012e ? 220 tbd a2.0f osc = 4 mhz xt oscillator mode ? 370 tbd a3.0 ? 0.6 tbd ma 5.0 d013e ? 70 tbd a2.0f osc = 1 mhz ec oscillator mode ? 140 tbd a3.0 ? 260 tbd a5.0 d014e ? 180 tbd a2.0f osc = 4 mhz ec oscillator mode ? 320 tbd a3.0 ? 500 tbd a5.0 d015e ? 5 tbd a2.0f osc = 31 khz intosc mode ?14tbd a3.0 ?30tbdma5.0 d016e ? 340 tbd a2.0f osc = 4 mhz intosc mode ? 500 tbd a3.0 ? 0.8 tbd ma 5.0 d017e ? 180 tbd a2.0f osc = 4 mhz extrc mode ? 320 tbd a3.0 ? 580 tbd a5.0 d018e ? 2.1 tbd ma 4.5 f osc = 20 mhz hs oscillator mode ? 3.0 tbd ma 5.0 legend: tbd = to be determined ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt disabled. 2: the supply current is mainly a function of the operating voltage and frequency. other factors, such as i/o pin loading and switching rate, oscillator type, internal code execution pattern and temperature, also have an impact on the current consumption. 3: the peripheral current is the sum of the base i dd or i pd and the additional current consumed when this peripheral is enabled. the peripheral current can be determined by subtracting the base i dd or i pd current from this limit. max values should be used when calculating total current consumption. 4: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd .
? 2005 microchip technology inc. advance information ds41250d-page 227 PIC16F917/916/914/913 d020e power-down base current (i pd ) (4) ?0.1tbd a 2.0 wdt, bor, comparators, v ref and t1osc disabled ?0.5tbd a3.0 ?0.75tbd a5.0 d021e ? 0.6 tbd a 2.0 wdt current ?1.8tbd a3.0 ?8.4tbd a5.0 d022e ? 58 tbd a 3.0 bor current ?75tbd a5.0 d023e ? 35 tbd a 2.0 comparator current (3) ?65tbd a3.0 ? 130 tbd a5.0 d024e ? 40 tbd a2.0cv ref current ?50.5tbd a3.0 ?80tbd a5.0 d025e ? 2.1 tbd a 2.0 t1osc current ?2.5tbd a3.0 ?3.4tbd a5.0 d026e ? 1.2 tbd a 3.0 a/d current (3) ? 0.0022 tbd a5.0 19.3 dc characteristics: PIC16F917/916/914/913-e (extended) (continued) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40 c t a +125 c for extended param no. device characteristics min typ? max units conditions v dd note legend: tbd = to be determined ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt disabled. 2: the supply current is mainly a function of the operating voltage and frequency. other factors, such as i/o pin loading and switching rate, oscillator type, internal code execution pattern and temperature, also have an impact on the current consumption. 3: the peripheral current is the sum of the base i dd or i pd and the additional current consumed when this peripheral is enabled. the peripheral current can be determined by subtracting the base i dd or i pd current from this limit. max values should be used when calculating total current consumption. 4: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd .
PIC16F917/916/914/913 ds41250d-page 228 advance information ? 2005 microchip technology inc. 19.4 dc characteristics: PIC16F917/916/914/913-i (industrial) PIC16F917/916/914/913-e (extended) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. sym characteristic min typ? max units conditions v il input low voltage i/o port: d030 with ttl buffer vss ? 0.8 v 4.5v v dd 5.5v d030a vss ? 0.15 v dd v otherwise d031 with schmitt trigger buffer vss ? 0.2 v dd v entire range d032 mclr , osc1 (rc mode) v ss ? 0.2 v dd v d033 osc1 (xt and lp modes) (1) v ss ?0.3v d033a osc1 (hs mode) (1) v ss ? 0.3 v dd v d034 i 2 c? mode v ss ?0.3v dd ventire v dd range v ih input high voltage i/o port: ? d040 d040a with ttl buffer 2.0 (0.25 v dd + 0.8) ? ? v dd v dd v v 4.5v v dd 5.5v otherwise d041 with schmitt trigger buffer 0.8 v dd ?v dd v entire range d042 mclr 0.8 v dd ?v dd v d043 osc1 (xt and lp modes) 1.6 ? v dd v (note 1) d043a osc1 (hs mode) 0.7 v dd ?v dd v (note 1) d043b osc1 (rc mode) 0.9 v dd ?v dd v d044 i 2 c mode 0.7v dd ?v dd ventire v dd range d070 i pur portb weak pull-up current 50* 250 400* av dd = 5.0v, v pin = v ss i il input leakage current (2) d060 i/o port ? 0 . 1 1 av ss v pin v dd , pin at high-impedance d061 mclr (3) ? 0 . 1 5 av ss v pin v dd d063 osc1 ? 0 . 1 5 av ss v pin v dd , xt, hs and lp osc configuration v ol output low voltage d080 i/o port ? ? 0.6 v i ol = 8.5 ma, v dd = 4.5v (ind.) d083 osc2/clko (rc mode) ? ? 0.6 v i ol = 1.6 ma, v dd = 4.5v (ind.) i ol = 1.2 ma, v dd = 4.5v (ext.) v oh output high voltage d090 i/o port v dd ? 0.7 ? ? v i oh = -3.0 ma, v dd = 4.5v (ind.) d092 osc2/clko (rc mode) v dd ? 0.7 ? ? v i oh = -1.3 ma, v dd = 4.5v (ind.) i oh = -1.0 ma, v dd = 4.5v (ext.) * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1/clki pin is a schmitt trigger input. it is not recommended to use an external clock in rc mode. 2: negative current is defined as current sourced by the pin. 3: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages.
? 2005 microchip technology inc. advance information ds41250d-page 229 PIC16F917/916/914/913 capacitive loading specs on output pins d100 cos c2 osc2 pin ? ? 15* pf in xt, hs and lp modes when external clock is used to drive osc1 d101 c io all i/o pins ? ? 50* pf data eeprom memory d120 e d byte endurance 100k 1m ? e/w -40 c t a +85c d120a e d byte endurance 10k 100k ? e/w +85c t a +125c d121 v drw v dd for read/write v min ? 5.5 v using eecon1 to read/write v min = minimum operating voltage d122 t dew erase/write cycle time ? 5 6 ms d123 t retd characteristic retention 40 ? ? year provided no other specifica- tions are violated d124 t ref number of total erase/write cycles before refresh (2) 1m 10m ? e/w -40 c t a +85c program flash memory d130 e p cell endurance 10k 100k ? e/w -40 c t a +85c d130a e d cell endurance 1k 10k ? e/w +85c t a +125c d131 v pr v dd for read v min ?5.5vv min = minimum operating voltage d132 v pew v dd for erase/write 4.5 ? 5.5 v d133 t pew erase/write cycle time ? 2 2.5 ms d134 t retd characteristic retention 40 ? ? year provided no other specifica- tions are violated 19.4 dc characteristics: PIC16F917/916/914/913-i (industrial) PIC16F917/916/914/913-e (extended) (continued) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. sym characteristic min typ? max units conditions * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1/clki pin is a schmitt trigger input. it is not recommended to use an external clock in rc mode. 2: negative current is defined as current sourced by the pin. 3: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages.
PIC16F917/916/914/913 ds41250d-page 230 advance information ? 2005 microchip technology inc. 19.5 timing parameter symbology the timing parameter symbols have been created with one of the following formats: figure 19-2: load conditions 1. tpps2pps 2. tpps t f frequency t time lowercase letters (pp) and their meanings: pp cc ccp1 osc osc1 ck clko rd rd cs cs rw rd or wr di sdi sc sck do sdo ss ss dt data in t0 t0cki io i/o port t1 t1cki mc mclr wr wr uppercase letters and their meanings: s ffall pperiod hhigh rrise i invalid (high-impedance) v valid l low z high-impedance v dd /2 c l r l pin pin v ss v ss c l r l = 464 c l = 50 pf for all pins 15 pf for osc2 output load condition 1 load condition 2 legend:
? 2005 microchip technology inc. advance information ds41250d-page 231 PIC16F917/916/914/913 19.6 ac characteristics: PIC16F917/916/914/913 (industrial, extended) figure 19-3: external clock timing table 19-1: external clock timing requirements standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristic min typ? max units conditions f osc external clki frequency (1) dc ? 37 khz lp oscillator mode dc ? 4 mhz xt oscillator mode dc ? 20 mhz hs oscillator mode dc ? 20 mhz ec oscillator mode oscillator frequency (1) 5 ? 37 khz lp oscillator mode ? 4 ? mhz intosc mode dc ? 4 mhz rc oscillator mode 0.1 ? 4 mhz xt oscillator mode 1 ? 20 mhz hs oscillator mode 1t osc external clki period (1) 27 ? ? s lp oscillator mode 50 ? ns hs oscillator mode 50 ? ns ec oscillator mode 250 ? ns xt oscillator mode oscillator period (1) 27 200 s lp oscillator mode ? 250 ? ns intosc mode 250 ? ? ns rc oscillator mode 250 ? 10,000 ns xt oscillator mode 50 ? 1,000 ns hs oscillator mode 2t cy instruction cycle time (1) 200 t cy dc ns t cy = 4/f osc 3tosl, to s h external clki (osc1) high external clki low 2* ? ? s lp oscillator, t osc l/h duty cycle 20* ? ? ns hs oscillator, t osc l/h duty cycle 100 * ? ? ns xt oscillator, t osc l/h duty cycle 4tosr, to s f external clki rise external clki fall ? ? 50* ns lp oscillator ? ? 25* ns xt oscillator ? ? 15* ns hs oscillator * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: instruction cycle period (t cy ) equals four times the input oscillator time base period. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator operation and/or higher than expected current consumption. all devices are tested to operate at ?min? values with an external clock applied to osc1 pin. when an external clock input is used, the ?max? cycle time limit is ?dc? (no clock) for all devices. osc1 clko q4 q1 q2 q3 q4 q1 1 2 3 3 4 4
PIC16F917/916/914/913 ds41250d-page 232 advance information ? 2005 microchip technology inc. table 19-2: precision internal oscillator parameters standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristic freq. tolerance min typ? max units conditions f10 f osc internal calibrated intosc frequency (1) 1% ? 8.00 tbd mhz v dd and temperature tbd 2% ? 8.00 tbd mhz 2.5v v dd 5.5v 0 c t a +85 c 5% ? 8.00 tbd mhz 2.0v v dd 5.5v -40 c t a +85 c (ind.) -40 c t a +125 c (ext.) f14 t iosc st oscillator wake-up from sleep start-up time* ??tbdtbd sv dd = 2.0v, -40 c to +85 c ??tbdtbd sv dd = 3.0v, -40 c to +85 c ??tbdtbd sv dd = 5.0v, -40 c to +85 c legend: tbd = to be determined * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: to ensure these oscillator frequency tolerances, v dd and v ss must be capacitively decoupled as close to the device as possible. 0.1 uf and 0.01 uf values in parallel are recommended.
? 2005 microchip technology inc. advance information ds41250d-page 233 PIC16F917/916/914/913 figure 19-4: clko and i/o timing table 19-3: clko and i/o timing requirements standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristic min typ? max units conditions 10* t os h2 ck losc1 to clout ? 75 200 ns (note 1) 11* t os h2 ck hosc1 to clout ? 75 200 ns (note 1) 12* t ck r clko rise time ? 35 100 ns (note 1) 13* t ck f clko fall time ? 35 100 ns (note 1) 14* t ck l2 io vclko to port out valid ? ? 0.5 t cy + 20 ns (note 1) 15* t io v2 ck h port in valid before clko t osc + 200 ns ? ? ns (note 1) 16* t ck h2 io i port in hold after clko 0 ? ? ns (note 1) 17* t os h2 io vosc1 (q1 cycle) to port out valid ? 50 150* ns ??300ns 18* t os h2 io iosc1 (q2 cycle) to port input invalid (i/o in hold time) 3.0-5.5v 100 ? ? ns 2.0-5.5v 200 ? ? ns 19* t io v2 os h port input valid to osc1 (i/o in setup time) 0??ns 20* t io r port output rise time 3.0-5.5v ? 10 40 ns 2.0-5.5v ? ? 145 21* t io f port output fall time 3.0-5.5v ? 10 40 ns 2.0-5.5v ? ? 145 22* t inp int pin high or low time 25 ? ? ns 23* t rbp porta change int high or low time t cy ??ns * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. note 1: measurements are taken in rc mode where clko output is 4 x t osc . osc1 clko i/o pin (input) i/o pin (output) q4 q1 q2 q3 10 13 14 17 20, 21 22 23 19 18 15 11 12 16 old value new value
PIC16F917/916/914/913 ds41250d-page 234 advance information ? 2005 microchip technology inc. figure 19-5: reset, watchdog timer, oscillator start-up timer and power-up timer timing figure 19-6: brown-out rese t timing and characteristics v dd mclr internal por pwrt time-out osc time-out internal reset watchdog timer reset 33 32 30 31 34 i/o pins 34 b vdd reset (due to bor) v dd (device in brown-out reset) (device not in brown-out reset) 64 ms time-out (1) 35 note 1: 64 ms delay only if pwrte bit in the configuration word is programmed to ? 0 ?.
? 2005 microchip technology inc. advance information ds41250d-page 235 PIC16F917/916/914/913 table 19-4: reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset requirements figure 19-7: timer0 and timer1 external clock timings standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristic min typ? max units conditions 30 t mc lmclr pulse width (low) 2 11 ? 18 ? 24 s ms v dd = 5v, -40c to +85c extended temperature 31 t wdt watchdog timer time-out period (no prescaler) 10 10 17 17 25 30 ms ms v dd = 5v, -40c to +85c extended temperature 32 t ost oscillation start-up timer period ? 1024 t osc ??t osc = osc1 period 33* t pwrt power-up timer period 28* tbd 64 tbd 132* tbd ms ms v dd = 5v, -40c to +85c extended temperature 34 t ioz i/o high-impedance from mclr low or watchdog timer reset ??2.0 s b vdd brown-out reset voltage 2.025 ? 2.175 v 35 t bor brown-out reset pulse width 100* ? ? sv dd b vdd (d005) legend: tbd = to be determined * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. t0cki t1cki 40 41 42 45 46 47 48 tmr0 or tmr1
PIC16F917/916/914/913 ds41250d-page 236 advance information ? 2005 microchip technology inc. table 19-5: timer0 and timer1 external clock requirements figure 19-8: usart synchronous transmission (master/slave) timing param no. sym characteristic min typ? max units conditions 40* t t 0h t0cki high pulse width no prescaler 0.5 t cy + 20 ? ? ns with prescaler 10 ? ? ns 41* t t 0l t0cki low pulse width no prescaler 0.5 t cy + 20 ? ? ns with prescaler 10 ? ? ns 42* t t 0p t0cki period greater of: 20 or t cy + 40 n ? ? ns n = prescale value (2, 4, ..., 256) 45* t t 1h t1cki high time synchronous, no prescaler 0.5 t cy + 20 ? ? ns synchronous, with prescaler 3.0-5.5v 15 ? ? ns 2.0-5.5v 25 ? ? ns asynchronous 3.0-5.5v 30 ? ? ns 2.0-5.5v 50 ? ? ns 46* t t 1l t1cki low time synchronous, no prescaler 0.5 t cy + 20 ? ? ns synchronous, with prescaler 3.0-5.5v 15 ? ? ns 2.0-5.5v 25 ? ? ns asynchronous 3.0-5.5v 30 ? ? ns 2.0-5.5v 50 ? ? ns 47* t t 1p t1cki input period synchronous 3.0-5.5v greater of: 30 or t cy + 40 n ? ? ns n = prescale value (1, 2, 4, 8) 2.0-5.5v 50 or t cy + 40 n ?? ns asynchronous 3.0-5.5v 60 ? ? ns 2.0-5.5v 100 ? ? ns f t 1 timer1 oscillator input frequency range (oscillator enabled by setting bit t1oscen) dc ? 37* khz 48 tckez tmr 1 delay from external clock edge to timer increment 2 t osc *?7 t osc *? * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note: refer to figure 19-2 for load conditions. 121 121 120 122 rc6/tx/ck rc7/rx/dt/ sck/scl/seg9 sdi/sda/seg8
? 2005 microchip technology inc. advance information ds41250d-page 237 PIC16F917/916/914/913 table 19-6: usart synchronous transmission requirements figure 19-9: usart synchronous receive (m aster/slave) timing table 19-7: usart synchronous receive requirements figure 19-10: capture/compare/pwm timings standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param. no. symbol characteristic min max units conditions 120 t ck h2 dt v sync xmit (m aster and s lave ) clock high to data-out valid 3.0-5.5v ? 80 ns 2.0-5.5v ? 100 ns 121 t ckrf clock out rise time and fall time (master mode) 3.0-5.5v ? 45 ns 2.0-5.5v ? 50 ns 122 t dtrf data-out rise time and fall time 3.0-5.5v ? 45 ns 2.0-5.5v ? 50 ns standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param. no. symbol characteristic min max units conditions 125 t dt v2 ckl sync rcv (m aster and s lave ) data-hold before ck (dt hold time) 10 ? ns 126 t ck l2 dtl data-hold after ck (dt hold time) 15 ? ns note: refer to figure 19-2 for load conditions. 125 126 rc6/tx/ck sck/scl/seg9 rc7/rx/dt/ sdi/sda/seg8 note: refer to figure 19-2 for load conditions. (capture mode) 50 51 52 53 54 ccp1/ccp2 (compare mode) ccp1/ccp2
PIC16F917/916/914/913 ds41250d-page 238 advance information ? 2005 microchip technology inc. table 19-8: capture/compare/pwm requirements table 19-9: comparator specifications table 19-10: comparator volt age reference specifications param. no. sym characteristic min typ? max units conditions 50* t cc l ccp1 input low time no prescaler 0.5t cy + 5 ? ? ns with prescaler 3.0-5.5v 10 ? ? ns 2.0-5.5v 20 ? ? ns 51* t cc h ccp1 input high time no prescaler 0.5t cy + 5 ? ? ns with prescaler 3.0-5.5v 10 ? ? ns 2.0-5.5v 20 ? ? ns 52* t cc p ccp1 input period 3t cy + 40 n ? ? ns n = prescale value (1,4 or 16) 53* t cc r ccp1 output fall time 3.0-5.5v ? 10 25 ns 2.0-5.5v ? 25 50 ns 54* t cc f ccp1 output fall time 3.0-5.5v ? 10 25 ns 2.0-5.5v ? 25 45 ns * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. comparator specifications standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c sym characteristics min typ max units comments v os input offset voltage ? 5.0 10 mv v cm input common mode voltage 0 ? v dd ? 1.5 v c mrr common mode rejection ratio +55* ? ? db t rt response time (1) ? 150 400* ns t mc 2 co v comparator mode change to output valid ?? 10* s * these parameters are characterized but not tested. note 1: response time measured with one comparator input at (v dd ? 1.5)/2 while the other input transitions from v ss to v dd ? 1.5v. voltage reference specifications standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c sym. characteristics min typ max units comments resolution ? ? v dd /24* v dd /32 ? ? lsb lsb low range (vrr = 1 ) high range (vrr = 0 ) absolute accuracy ? ? ? ? 1/4* 1/2* lsb lsb low range (vrr = 1 ) high range (vrr = 0 ) unit resistor value (r) ? 2k* ? settling time (1) ?? 10* s * these parameters are characterized but not tested. note 1: settling time measured while vrr = 1 and vr<3:0> transitions from ? 0000 ? to ? 1111 ?.
? 2005 microchip technology inc. advance information ds41250d-page 239 PIC16F917/916/914/913 table 19-11: PIC16F917/916/914/913 plvd characteristics : dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c operating voltage v dd range 2.0v-5.5v sym. characteristic min typ? max units conditions v plvd plvd voltage lvdl<2:0> = 000 tbd 1.9 tbd v tbd tbd 2.0 tbd v tbd tbd 2.1 tbd v tbd tbd 2.2 tbd v tbd tbd 2.3 tbd v tbd tbd 4.0 tbd v tbd tbd 4.2 tbd v tbd tbd 4.5 tbd v legend: tbd = to be determined ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested.
PIC16F917/916/914/913 ds41250d-page 240 advance information ? 2005 microchip technology inc. figure 19-11: spi? master mode timing (cke = 0 , smp = 0 ) figure 19-12: spi? master mode timing (cke = 1 , smp = 1 ) ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 70 71 72 73 74 75, 76 78 79 80 79 78 msb lsb bit 6 - - - - - -1 msb in lsb in bit 6 - - - -1 note: refer to figure 19-2 for load conditions. ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 81 71 72 74 75, 76 78 80 msb 79 73 msb in bit 6 - - - - - -1 lsb in bit 6 - - - -1 lsb note: refer to figure 19-2 for load conditions.
? 2005 microchip technology inc. advance information ds41250d-page 241 PIC16F917/916/914/913 figure 19-13: spi? slave mode timing (cke = 0 ) figure 19-14: spi? slave mode timing (cke = 1 ) ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 70 71 72 73 74 75, 76 77 78 79 80 79 78 msb lsb bit 6 - - - - - -1 msb in bit 6 - - - -1 lsb in 83 note: refer to figure 19-2 for load conditions. ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 70 71 72 82 74 75, 76 msb bit 6 - - - - - -1 lsb 77 msb in bit 6 - - - -1 lsb in 80 83 note: refer to figure 19-2 for load conditions.
PIC16F917/916/914/913 ds41250d-page 242 advance information ? 2005 microchip technology inc. table 19-12: spi? mode requirements figure 19-15: i 2 c? bus start/stop bits timing param no. symbol characteristic min typ? max units conditions 70* t ss l2 sc h, t ss l2 sc l ss to sck or sck input t cy ??ns 71* t sc h sck input high time (slave mode) t cy + 20 ? ? ns 72* t sc l sck input low time (slave mode) t cy + 20 ? ? ns 73* t di v2 sc h, t di v2 sc l setup time of sdi data input to sck edge 100 ? ? ns 74* t sc h2 di l, t sc l2 di l hold time of sdi data input to sck edge 100 ? ? ns 75* t do r sdo data output rise time 3.0-5.5v ? 10 25 ns 2.0-5.5v ? 25 50 ns 76* t do f sdo data output fall time ? 10 25 ns 77* t ss h2 do zss to sdo output high-impedance 10 ? 50 ns 78* t sc r sck output rise time (master mode) 3.0-5.5v ? 10 25 ns 2.0-5.5v ? 25 50 ns 79* t sc f sck output fall time (master mode) ? 10 25 ns 80* t sc h2 do v, t sc l2 do v sdo data output valid after sck edge 3.0-5.5v ? ? 50 ns 2.0-5.5v ? ? 145 ns 81* t do v2 sc h, t do v2 sc l sdo data output setup to sck edge tcy ? ? ns 82* t ss l2 do v sdo data output valid after ss edge ? ? 50 ns 83* t sc h2 ss h, t sc l2 ss h ss after sck edge 1.5t cy + 40 ? ? ns * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note : refer to figure 19-2 for load conditions. 91 92 93 scl sda start condition stop condition 90
? 2005 microchip technology inc. advance information ds41250d-page 243 PIC16F917/916/914/913 table 19-13: i 2 c? bus start/stop bits requirements figure 19-16: i 2 c? bus data timing param no. symbol characteristic min typ max units conditions 90* t su : sta start condition 100 khz mode 4700 ? ? ns only relevant for repeated start condition setup time 400 khz mode 600 ? ? 91* t hd : sta start condition 100 khz mode 4000 ? ? ns after this period, the first clock pulse is generated hold time 400 khz mode 600 ? ? 92* t su : sto stop condition 100 khz mode 4700 ? ? ns setup time 400 khz mode 600 ? ? 93 t hd : sto stop condition 100 khz mode 4000 ? ? ns hold time 400 khz mode 600 ? ? * these parameters are characterized but not tested. note: refer to figure 19-2 for load conditions. 90 91 92 100 101 103 106 107 109 109 110 102 scl sda in sda out
PIC16F917/916/914/913 ds41250d-page 244 advance information ? 2005 microchip technology inc. table 19-14: i 2 c? bus data requirements param. no. symbol characteristic min max units conditions 100* t high clock high time 100 khz mode 4.0 ? s device must operate at a minimum of 1.5 mhz 400 khz mode 0.6 ? s device must operate at a minimum of 10 mhz ssp module 1.5t cy ? 101* t low clock low time 100 khz mode 4.7 ? s device must operate at a minimum of 1.5 mhz 400 khz mode 1.3 ? s device must operate at a minimum of 10 mhz ssp module 1.5t cy ? 102* t r sda and scl rise time 100 khz mode ? 1000 ns 400 khz mode 20 + 0.1c b 300 ns c b is specified to be from 10-400 pf 103* t f sda and scl fall time 100 khz mode ? 300 ns 400 khz mode 20 + 0.1c b 300 ns c b is specified to be from 10-400 pf 90* t su : sta start condition setup time 100 khz mode 4.7 ? s only relevant for repeated start condition 400 khz mode 0.6 ? s 91* t hd : sta start condition hold time 100 khz mode 4.0 ? s after this period the first clock pulse is generated 400 khz mode 0.6 ? s 106* t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 s 107* t su : dat data input setup time 100 khz mode 250 ? ns (note 2) 400 khz mode 100 ? ns 92* t su : sto stop condition setup time 100 khz mode 4.7 ? s 400 khz mode 0.6 ? s 109* t aa output valid from clock 100 khz mode ? 3500 ns (note 1) 400 khz mode ? ? ns 110* t buf bus free time 100 khz mode 4.7 ? s time the bus must be free before a new transmission can start 400 khz mode 1.3 ? s c b bus capacitive loading ? 400 pf * these parameters are characterized but not tested. note 1: as a transmitter, the device must provide this internal minimum delay time to bridge the undefined region (min. 300 ns) of the falling edge of scl to avoid unintended generation of start or stop conditions. 2: a fast mode (400 khz) i 2 c bus device can be used in a standard mode (100 khz) i 2 c bus system, but the requirement t su : dat 250 ns must then be met. this will automatically be the case if the device does not stretch the low period of the scl signal. if such a device does stretch the low period of the scl signal, it must output the next data bit to the sda line t r max. + t su : dat = 1000 + 250 = 1250 ns (according to the standard mode i 2 c bus specification), before the scl line is released.
? 2005 microchip technology inc. advance information ds41250d-page 245 PIC16F917/916/914/913 table 19-15: PIC16F917/916/914/913 a/d converter characteristics : figure 19-17: PIC16F917/916/914/913 a/d conversion timing (normal mode) standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristic min typ? max units conditions a01 n r resolution ? ? 10 bits bits a03 e il integral error ? ? < 1lsbv ref = 5.0v a04 e dl differential error ? ? < 1 lsb no missing codes to 10 bits v ref = 5.0v a06 e off offset error ? ? < 1lsbv ref = 5.0v a07 e gn gain error ? ? < 1lsbv ref = 5.0v a10 ? monotonicity ? assured (1) ??v ss v ain v ref + a20 v ref reference voltage (v ref + ? v ref -) 2.5 ? v dd v full 10-bit accuracy a21 v ref + reference voltage high v dd ? 2.5v ? v dd + 0.3v v a22 v ref - reference voltage low v ss ? 0.3v ? v ref + -2v v a25 v ain analog input voltage v ss ? 0.3v ? v ref + +0.3v v a30 z ain recommended imped- ance of analog voltage source ?? 10k a50 i ref v ref input current (2) ?? 5 150 a a during v ain acquisition. during a/d conversion cycle. * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: the a/d conversion result never decreases with an increase in the input voltage and has no missing codes. 2: v ref + current is from ra3/an3/c1+/v ref +/seg15 pin or v dd , whichever is selected as the v ref + source. v ref - current is from ra2/an2/c2+/v ref -/com2 pin or v ss , whichever is selected as the v ref - source. 131 130 132 bsf adcon0, go q4 a/d clk a/d data adres adif go sample old_data sampling stopped done new_data 987 3210 note 1: if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. 1 t cy 6 134 (t osc /2) (1) 1 t cy
PIC16F917/916/914/913 ds41250d-page 246 advance information ? 2005 microchip technology inc. table 19-16: PIC16F917/916/914/913 a/d conversion requirements standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristic min typ? max units conditions 130 t ad a/d clock period (2) 1.6 ? ? st osc -based, v ref 3.0v 3.0* ? ? st osc -based, v ref full range 130 t ad a/d internal rc oscillator period 3.0* 6.0 9.0* s adcs<1:0> = 11 (rc mode) at v dd = 2.5v 2.0* 4.0 6.0* sat v dd = 5.0v 131 t cnv conversion time (not including acquisition time) (1) ?11?t ad set go/done bit to new data in a/d result register 132 t acq acquisition time 5* 11.5 ? ? ? s s the minimum time is the amplifier settling time. this may be used if the ?new? input voltage has not changed by more than 1 lsb (i.e., 4.1 mv @ 4.096v) from the last sampled voltage (as stored on c hold ). 134 t go q4 to a/d clock start ?t osc /2 ? ? if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: adresh and adresl registers may be read on the following t cy cycle. 2: see table 12-1 for minimum conditions.
? 2005 microchip technology inc. preliminary ds41250d-page 247 PIC16F917/916/914/913 20.0 dc and ac characteristics graphs and tables graphs are not available at this time.
PIC16F917/916/914/913 ds41250d-page 248 preliminary ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. preliminary ds41250d-page 249 PIC16F917/916/914/913 21.0 packaging information 21.1 package marking information * standard picmicro ? device marking consists of microchip part number, year code, week code and traceability code. for picmicro device marking beyond this, certain price adders apply. please check with your microchip sales office. for qtp devices, any special marking adders are included in qtp price. 40-lead pdip xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx yywwnnn example pic16f914-i/p 0410017 example 28-lead qfn xxxxxxxx xxxxxxxx yywwnnn 16f916 -i/ml 0410017 28-lead spdip xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx yywwnnn example pic16f913-i/sp 0410017 legend: xx...x customer-specific information y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code pb-free jedec designator for matte tin (sn) * this package is pb-free. the pb-free jedec designator ( ) can be found on the outer packaging for this package. note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line, thus limiting the number of available characters for customer-specific information. 3 e 3 e
PIC16F917/916/914/913 ds41250d-page 250 preliminary ? 2005 microchip technology inc. package marking information (continued) 28-lead soic xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx yywwnnn example pic16f913-i/so 0410017 28-lead ssop xxxxxxxxxxxx xxxxxxxxxxxx yywwnnn example pic16f916-i/ss 0410017 xxxxxxxxxx 44-lead qfn xxxxxxxxxx xxxxxxxxxx yywwnnn example pic16f914 -i/ml 0410017 44-lead tqfp xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx yywwnnn example PIC16F917-i/pt 0310017
? 2005 microchip technology inc. preliminary ds41250d-page 251 PIC16F917/916/914/913 21.2 package details the following sections give the technical details of the packages. 28-lead skinny plastic dual in-line (sp) ? 300 mil body (pdip) 15 10 5 15 10 5 mold draft angle bottom 15 10 5 15 10 5 mold draft angle top 10.92 8.89 8.13 .430 .350 .320 eb overall row spacing 0.56 0.48 0.41 .022 .019 .016 b lower lead width 1.65 1.33 1.02 .065 .053 .040 b1 upper lead width 0.38 0.29 0.20 .015 .012 .008 c lead thickness 3.43 3.30 3.18 .135 .130 .125 l tip to seating plane 35.18 34.67 34.16 1.385 1.365 1.345 d overall length 7.49 7.24 6.99 .295 .285 .275 e1 molded package width 8.26 7.87 7.62 .325 .310 .300 e shoulder to shoulder width 0.38 .015 a1 base to seating plane 3.43 3.30 3.18 .135 .130 .125 a2 molded package thickness 4.06 3.81 3.56 .160 .150 .140 a top to seating plane 2.54 .100 p pitch 28 28 n number of pins max nom min max nom min dimension limits millimeters inches* units 2 1 d n e1 c eb e p l a2 b b1 a a1 notes: jedec equivalent: mo-095 drawing no. c04-070 * controlling parameter dimension d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. significant characteristic
PIC16F917/916/914/913 ds41250d-page 252 preliminary ? 2005 microchip technology inc. 40-lead plastic dual in-line (p) ? 600 mil body (pdip) 15 10 5 15 10 5 mold draft angle bottom 15 10 5 15 10 5 mold draft angle top 17.27 16.51 15.75 .680 .650 .620 eb overall row spacing 0.56 0.46 0.36 .022 .018 .014 b lower lead width 1.78 1.27 0.76 .070 .050 .030 b1 upper lead width 0.38 0.29 0.20 .015 .012 .008 c lead thickness 3.43 3.30 3.05 .135 .130 .120 l tip to seating plane 52.45 52.26 51.94 2.065 2.058 2.045 d overall length 14.22 13.84 13.46 .560 .545 .530 e1 molded package width 15.88 15.24 15.11 .625 .600 .595 e shoulder to shoulder width 0.38 .015 a1 base to seating plane 4.06 3.81 3.56 .160 .150 .140 a2 molded package thickness 4.83 4.45 4.06 .190 .175 .160 a top to seating plane 2.54 .100 p pitch 40 40 n number of pins max nom min max nom min dimension limits millimeters inches* units a2 1 2 d n e1 c eb e p l b b1 a a1 * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: mo-011 drawing no. c04-016 significant characteristic
? 2005 microchip technology inc. preliminary ds41250d-page 253 PIC16F917/916/914/913 28-lead plastic quad flat no lead package (ml) 6x6 mm body (qfn) ? with 0.55 mm contact length (saw singulated) contact width *controlling parameter drawing no. c04-105 notes: jedec equivalent: mo-220 b .009 .011 .013 0.23 0.28 0.33 pitch number of pins overall width standoff overall length overall height max units dimension limits a1 d e n e a .000 inches .026 bsc min 28 nom max .002 0.00 6.00 millimeters* .039 min 28 0.65 bsc nom 0.05 1.00 0.90 .035 .001 0.02 contact length l .020 .024 .028 0.50 0.60 0.70 e2 d2 exposed pad width exposed pad length .140 .146 .152 3.55 3.70 3.85 .031 0.80 5.90 6.10 .240 .236 .232 .232 .236 6.00 .240 5.90 6.10 .140 .146 3.70 .152 3.55 3.85 b d2 d pad outline alternate see detail a1 a detail top view optional index area 1 2 l bottom view n e metal pad alternate exposed indicators index e e2 revised 05-24-04 contact thickness a3 .008 ref 0.20 ref
PIC16F917/916/914/913 ds41250d-page 254 preliminary ? 2005 microchip technology inc. 28-lead plastic quad flat no lead package (ml) 6x6x0.9 mm body (qfn-s) ? with 0.40 mm contact length (saw singulated) lead width *controlling parameter drawing no. c04-124 notes: jedec equivalent: mo-220 b .013 .015 .017 0.33 0.38 0.43 pitch number of pins overall width standoff overall length overall height max units dimension limits a1 d e n e a .000 inches .026 bsc min 28 nom max .002 0.00 6.00 millimeters* .039 min 28 0.65 bsc nom 0.05 1.00 0.90 .035 .001 0.02 lead length l .012 .016 .020 0.30 0.40 0.50 e2 d2 exposed pad width exposed pad length .169 .175 .177 4.30 4.45 4.50 .031 0.80 5.90 6.10 .240 .236 .232 .232 .236 6.00 .240 5.90 6.10 .169 .175 4.45 .177 4.30 4.50 b d2 d a1 a top view optional index area 1 2 l bottom view n e metal pad alternate exposed indicators index e e2 revised 05/24/04
? 2005 microchip technology inc. preliminary ds41250d-page 255 PIC16F917/916/914/913 44-lead plastic quad flat no lead package (ml) 8x8 mm body (qfn)
PIC16F917/916/914/913 ds41250d-page 256 preliminary ? 2005 microchip technology inc. 28-lead plastic small outline (so) ? wide, 300 mil body (soic) foot angle top 048048 15 12 0 15 12 0 mold draft angle bottom 15 12 0 15 12 0 mold draft angle top 0.51 0.42 0.36 .020 .017 .014 b lead width 0.33 0.28 0.23 .013 .011 .009 c lead thickness 1.27 0.84 0.41 .050 .033 .016 l foot length 0.74 0.50 0.25 .029 .020 .010 h chamfer distance 18.08 17.87 17.65 .712 .704 .695 d overall length 7.59 7.49 7.32 .299 .295 .288 e1 molded package width 10.67 10.34 10.01 .420 .407 .394 e overall width 0.30 0.20 0.10 .012 .008 .004 a1 standoff 2.39 2.31 2.24 .094 .091 .088 a2 molded package thickness 2.64 2.50 2.36 .104 .099 .093 a overall height 1.27 .050 p pitch 28 28 n number of pins max nom min max nom min dimension limits millimeters inches* units 2 1 d p n b e e1 l c 45 h a2 a a1 * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: ms-013 drawing no. c04-052 significant characteristic
? 2005 microchip technology inc. preliminary ds41250d-page 257 PIC16F917/916/914/913 28-lead plastic shrink small outline (ss) ? 209 mil body, 5.30 mm (ssop) 0.38 - 0.22 .015 - .009 b lead width 8 4 0 8 4 0 f foot angle 0.25 - 0.09 .010 - .004 c lead thickness 0.95 0.75 0.55 .037 .030 .022 l foot length 10.50 10.20 9.90 .413 .402 .390 d overall length 5.60 5.30 5.00 .220 .209 .009 e1 molded package width 8.20 7.80 7.49 .323 .307 .295 e overall width - - 0.05 - - .002 a1 standoff 1.85 1.75 1.65 .073 .069 .065 a2 molded package thickness 2.0 - - .079 - - a overall height 0.65 .026 p pitch 28 28 n number of pins max nom min max nom min dimension limits millimeters* inches units 2 1 d p n b e1 e l c f a2 a1 a shall not exceed .010" (0.254mm) per side. dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions notes: jedec equivalent: mo-150 drawing no. c04-073 *controlling parameter
PIC16F917/916/914/913 ds41250d-page 258 preliminary ? 2005 microchip technology inc. 44-lead plastic thin quad flatpack (pt) 10x10x1 mm body, 1.0/0.10 mm lead form (tqfp) * controlling parameter notes: dimensions d1 and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: ms-026 drawing no. c04-076 1.14 0.89 0.64 .045 .035 .025 ch pin 1 corner chamfer 1.00 .039 (f) footprint (reference) (f) a a1 a2 e e1 #leads=n1 p b d1 d n 1 2 c l units inches millimeters* dimension limits min nom max min nom max number of pins n 44 44 pitch p .031 0.80 overall height a .039 .043 .047 1.00 1.10 1.20 molded package thickness a2 .037 .039 .041 0.95 1.00 1.05 standoff a1 .002 .004 .006 0.05 0.10 0.15 foot length l .018 .024 .030 0.45 0.60 0.75 foot angle 03.5 7 03.5 7 overall width e .463 .472 .482 11.75 12.00 12.25 overall length d .463 .472 .482 11.75 12.00 12.25 molded package width e1 .390 .394 .398 9.90 10.00 10.10 molded package length d1 .390 .394 .398 9.90 10.00 10.10 pins per side n1 11 11 lead thickness c .004 .006 .008 0.09 0.15 0.20 lead width b .012 .015 .017 0.30 0.38 0.44 mold draft angle top 51015 51015 mold draft angle bottom 51015 51015 ch x 45 significant characteristic
? 2005 microchip technology inc. preliminary ds41250d-page 259 PIC16F917/916/914/913 appendix a: data sheet revision history revision a this is a new data sheet. revision b updated peripheral features. page 2, table: corrected i/o numbers. figure 8-3: revised comparator i/o operating modes. register 9-1, table: corrected max. number of pixels. revision c correction to pin description table. correction to ipd base and t1osc. revision d revised references 31.25 khz to 31 khz. revised standby current to 100 na. revised 9.1: internal rc oscillator to internal lf oscillator. appendix b: migrating from other picmicro ? devices this discusses some of the issues in migrating from other picmicro devices to the PIC16F917/916/914/913 family of devices. b.1 pic16f676 to PIC16F917/916/914/ 913 table b-1: feature comparison feature pic16f676 PIC16F917/ 916/914/913 max operating speed 20 mhz 20 mhz max program memory (words) 1k 8k max sram (bytes) 64 352 a/d resolution 10-bit 10-bit data eeprom (bytes) 128 256 timers (8/16-bit) 1/1 2/1 oscillator modes 8 8 brown-out reset y y internal pull-ups rb0/1/2/4/5 rb<7:0> interrupt-on-change rb0/1/2/3 /4/5 rb<7:4> comparator 1 2 usart n y extended wdt n y software control option of wdt/bor ny intosc frequencies 4 mhz 32 khz - 8mhz clock switching n y
PIC16F917/916/914/913 ds41250d-page 260 preliminary ? 2005 microchip technology inc. appendix c: conversion considerations considerations for converting from previous versions of devices to the ones listed in this data sheet are listed in table c-1. table c-1: conversion considerations characteristic PIC16F917/916/914/913 pic16f87x pic16f87xa pins 28/40 28/40 28/40 timers 3 3 3 interrupts 11 or 12 13 or 14 14 or 15 communication usart, ssp (spi?, i 2 c? slave) psp, usart, ssp (spi, i 2 c master/slave) psp, usart, ssp (spi, i 2 c master/slave) frequency 20 mhz 20 mhz 20 mhz voltage 2.0v-5.5v 2.2v-5.5v 2.0v-5.5v a/d 10-bit, 7 conversion clock selects 10-bit, 4 conversion clock selects 10-bit, 7 conversion clock selects ccp 2 2 2 comparator 2 ? 2 comparator voltage reference yes ? yes program memory 4k, 8k eprom 4k, 8k flash (erase/write on single-word) 4k, 8k flash (erase/write on four-word blocks) ram 256, 352 bytes 192, 368 bytes 192, 368 bytes eeprom data 256 bytes 128, 256 bytes 128, 256 bytes code protection on/off segmented, starting at end of program memory on/off program memory write protection ? on/off segmented, starting at beginning of program memory lcd module 16, 24 segment drivers, 4 commons ?? other in-circuit debugger, low-voltage programming in-circuit debugger, low-voltage programming in-circuit debugger, low-voltage programming
? 2005 microchip technology inc. preliminary ds41250d-page 261 PIC16F917/916/914/913 index a a/d acquisition requirements ......................................... 149 analog port pins ....................................................... 144 associated registers ................................................ 151 block diagram........................................................... 143 calculating acquisition time..................................... 149 channel selection..................................................... 144 configuration and operation..................................... 144 configuring................................................................ 148 configuring interrupt ................................................. 148 conversion (t ad ) cycles .......................................... 145 conversion clock...................................................... 144 effects of reset......................................................... 151 internal sampling switch (r ss ) impedance.............. 149 operation during sleep ............................................ 150 output format........................................................... 145 reference voltage (v ref )......................................... 144 source impedance.................................................... 149 specifications............................................................ 246 starting a conversion ............................................... 145 t ad vs. operating frequencies................................. 144 absolute maximum ratings .............................................. 221 ac characteristics industrial and extended ............................................ 231 load conditions ........................................................ 230 ack pulse ......................................................................... 169 adcon0 register............................................................. 146 adcon1 register............................................................. 147 addressable universal sync hronous asynchronous receiver transmitter. see usart analog input connections ................................................... 94 analog-to-digital converter module. see a/d ansel register................................................................ 146 assembler mpasm assembler................................................... 215 asynchronous reception associated registers ........................................ 135, 137 asynchronous transmission associated registers ................................................ 133 b baud rate generator associated registers ................................................ 129 bf bit................................................................................. 160 block diagrams a/d ............................................................................ 143 analog input model ............................................. 94, 150 capture mode ........................................................... 179 comparator 1 .............................................................. 96 comparator 2 .............................................................. 96 comparator modes ..................................................... 95 comparator voltage reference (cv ref ) .................... 98 compare mode ......................................................... 180 fail-safe clock monitor (fscm) ................................. 79 in-circuit serial programming connections.............. 203 interrupt logic ........................................................... 196 lcd clock generation .............................................. 108 lcd driver module ................................................... 102 lcd resistor ladder connection ............................. 106 mclr circuit............................................................. 188 on-chip reset circuit ............................................... 187 pic16f913/916............................................................. 8 pic16f914/917............................................................. 9 pwm mode............................................................... 181 ra0 pin ...................................................................... 33 ra1 pin ...................................................................... 34 ra2 pin ...................................................................... 35 ra3 pin ...................................................................... 36 ra4 pin ...................................................................... 37 ra5 pin ...................................................................... 38 ra6 pin ...................................................................... 39 ra7 pin ...................................................................... 40 rb pins....................................................................... 45 rb4 pin ...................................................................... 46 rb5 pin ...................................................................... 47 rb6 pin ...................................................................... 48 rb7 pin ...................................................................... 49 rc0 pin ...................................................................... 52 rc1 pin ...................................................................... 53 rc2 pin ...................................................................... 53 rc3 pin ...................................................................... 54 rc4 pin ...................................................................... 55 rc5 pin ...................................................................... 56 rc6 pin ...................................................................... 57 rc7 pin ...................................................................... 58 rd pins ...................................................................... 63 rd0 pin ...................................................................... 62 rd1 pin ...................................................................... 62 rd2 pin ...................................................................... 63 re pins....................................................................... 66 resonator operation .................................................. 74 ssp (i 2 c mode)........................................................ 169 ssp (spi mode) ....................................................... 162 system clock.............................................................. 69 timer1 ........................................................................ 85 timer2 ........................................................................ 91 tmr0/wdt prescaler ................................................ 81 usart receive ............................................... 135, 136 usart transmit ...................................................... 132 watchdog timer (wdt)............................................ 199 brgh bit .......................................................................... 129 brown-out reset (bor).................................................... 189 associated registers................................................ 190 calibration ................................................................ 189 specifications ........................................................... 235 timing and characteristics ....................................... 234 c c compilers mplab c17.............................................................. 216 mplab c18.............................................................. 216 mplab c30.............................................................. 216 capture/compare/pwm (ccp) ........................................ 177 associated registers capture, compare and timer1......................... 182 pwm and timer2.............................................. 183 capture mode........................................................... 179 block diagram .................................................. 179 ccp1con register.......................................... 178 ccp1if............................................................. 179 prescaler .......................................................... 179 ccp timer resources.............................................. 177 compare special trigger output of ccp1 ....................... 180 special trigger output of ccp2 ....................... 180 compare mode......................................................... 180 block diagram .................................................. 180
PIC16F917/916/914/913 ds41250d-page 262 preliminary ? 2005 microchip technology inc. software interrupt mode ................................... 180 special event trigger........................................ 180 interaction of two ccp modules (table) ................... 177 pwm mode ............................................................... 180 block diagram................................................... 181 duty cycle......................................................... 181 example frequencies/resolutions (table) ........ 182 pwm period...................................................... 181 special event trigger and a/d conversions............. 180 ccp. see capture/compare/pwm ccp1con register .................................................... 64, 178 ccpr1h register ............................................................. 177 ccpr1l register.............................................................. 177 ccpxm0 bit ....................................................................... 178 ccpxm1 bit ....................................................................... 178 ccpxm2 bit ....................................................................... 178 ccpxm3 bit ....................................................................... 178 ccpxx bit.......................................................................... 178 ccpxy bit.......................................................................... 178 cke bit .............................................................................. 160 ckp bit .............................................................................. 161 cmcon0 register .............................................................. 93 cmcon1 register .............................................................. 97 code examples a/d conversion ......................................................... 148 assigning prescaler to timer0 .................................... 83 assigning prescaler to wdt ....................................... 83 call of a subroutine in page 1 from page 0................ 29 indirect addressing ..................................................... 30 initializing porta....................................................... 31 initializing portb....................................................... 41 initializing portc....................................................... 51 initializing portd....................................................... 60 initializing porte....................................................... 65 loading the sspbuf (sspsr) register .................. 163 saving status and w registers in ram ................... 198 code protection ................................................................ 203 comparator module ............................................................ 93 comparator voltage reference (cv ref ) associated registers ................................................ 100 effects of a reset........................................................ 99 response time ........................................................... 99 comparator voltage reference (cv ref ) ............................ 98 accuracy/error ............................................................ 98 configuring.................................................................. 98 specifications............................................................ 238 comparators associated registers ................................................ 100 c2out as t1 gate ............................................... 86, 97 configurations............................................................. 95 effects of a reset........................................................ 99 interrupts..................................................................... 97 operation .................................................................... 94 operation during sleep .............................................. 99 outputs ....................................................................... 97 response time ........................................................... 99 specifications............................................................ 238 synchronizing c2out w/ timer1 ............................... 97 config register.............................................................. 186 configuration bits.............................................................. 186 conversion considerations ............................................... 260 cpu features ................................................................... 185 customer change notification service ............................. 269 customer notification service........................................... 269 customer support ............................................................. 269 d d/a bit ............................................................................... 160 data eeprom memory.................................................... 153 associated registers ................................................ 158 reading .................................................................... 156 writing ...................................................................... 156 data memory ...................................................................... 14 data/address bit (d/a )...................................................... 160 dc characteristics extended and industrial ............................................ 228 industrial and extended ............................................ 223 demonstration boards picdem 1................................................................. 218 picdem 17............................................................... 219 picdem 18r ............................................................ 219 picdem 2 plus......................................................... 218 picdem 3................................................................. 218 picdem 4................................................................. 218 picdem lin ............................................................. 219 picdem usb ........................................................... 219 picdem.net internet/ethernet .................................. 218 development support ....................................................... 215 device overview................................................................... 7 e eeadrh registers................................................... 153, 154 eeadrl registers ................................................... 153, 154 eecon1 register..................................................... 153, 155 eecon2 register............................................................. 153 eedath register............................................................. 154 eedatl register ............................................................. 154 electrical specifications .................................................... 221 enhanced capture/compare/pwm (eccp) enhanced pwm mode tmr2 to pr2 match ........................................... 90 errata .................................................................................... 5 evaluation and programming tools.................................. 219 f fail-safe clock monitor ...................................................... 79 fail-safe condition clearing....................................... 80 reset and wake-up from sleep.................................. 80 firmware instructions ....................................................... 205 flash program memory .................................................... 153 fuses. see configuration bits g general purpose register file ........................................... 14 i i/o ports.............................................................................. 31 i 2 c mode addressing................................................................ 170 associated registers ................................................ 176 master mode............................................................. 175 mode selection ......................................................... 169 multi-master mode .................................................... 175 operation .................................................................. 169 reception ................................................................. 171 slave mode scl and sda pins............................................ 169 transmission ............................................................ 173 id locations...................................................................... 203 in-circuit debugger........................................................... 204 in-circuit serial programming (icsp)............................... 203
? 2005 microchip technology inc. preliminary ds41250d-page 263 PIC16F917/916/914/913 indirect addressing, indf and fsr registers ................... 30 instruction format ............................................................. 206 instruction set ................................................................... 205 addlw ..................................................................... 208 addwf..................................................................... 208 andlw ..................................................................... 208 andwf..................................................................... 208 bcf........................................................................... 208 bsf ........................................................................... 208 btfsc ...................................................................... 209 btfss ...................................................................... 208 call ......................................................................... 209 clrf......................................................................... 209 clrw ....................................................................... 209 clrwdt................................................................... 209 comf ....................................................................... 209 decf ........................................................................ 209 decfsz.................................................................... 210 goto ....................................................................... 210 incf.......................................................................... 210 incfsz ..................................................................... 210 iorlw ...................................................................... 210 iorwf ...................................................................... 210 movf........................................................................ 211 movlw .................................................................... 211 movwf .................................................................... 211 nop .......................................................................... 211 retfie ..................................................................... 212 retlw ..................................................................... 212 return ................................................................... 212 rlf ........................................................................... 213 rrf........................................................................... 213 sleep ...................................................................... 213 sublw ..................................................................... 213 subwf ..................................................................... 213 swapf ..................................................................... 214 xorlw..................................................................... 214 xorwf..................................................................... 214 summary table......................................................... 207 intcon register................................................................ 23 inter-integrated circuit (i 2 c). see i 2 c mode internal oscillator block intosc specifications.................................................... 232 internal sampling switch (rss) impedance ...................... 149 internet address................................................................ 269 interrupt sources usart receive/transmit complete ........................ 127 interrupts........................................................................... 195 a/d ............................................................................ 148 associated registers ................................................ 197 comparators ............................................................... 97 context saving.......................................................... 198 interrupt-on-change .................................................... 41 portb interrupt-on-change .................................... 196 rb0/int/seg0.......................................................... 196 tmr0 ........................................................................ 196 tmr1 .......................................................................... 86 tmr2 to pr2 match ................................................... 91 tmr2 to pr2 match (pwm) ....................................... 90 intosc specifications ..................................................... 232 iocb register..................................................................... 42 l lcd associated registers................................................ 124 bias types................................................................ 106 clock source selection ............................................ 106 configuring the module ............................................ 124 frame frequency ..................................................... 107 interrupts .................................................................. 121 lcdcon register .................................................... 101 lcddata register .................................................. 101 lcdps register ....................................................... 101 lcdse register ....................................................... 101 multiplex types......................................................... 107 operation during sleep ............................................ 122 pixel control ............................................................. 107 prescaler .................................................................. 106 segment enables ..................................................... 107 waveform generation .............................................. 110 lcdcon register ............................................................ 101 lcddata register........................................................... 101 lcdps register ............................................................... 101 lp bits ...................................................................... 106 lcdse register ............................................................... 101 liquid crystal display (lcd) driver .................................. 101 load conditions................................................................ 230 m mclr ............................................................................... 188 internal...................................................................... 188 memory organization ......................................................... 13 data ............................................................................ 14 program...................................................................... 13 microchip internet web site.............................................. 269 migrating from other picmicro devices ............................ 259 mplab asm30 assembler, linker, librarian ................... 216 mplab icd 2 in-circuit debugger ................................... 217 mplab ice 2000 high-performance universal in-circuit emulator................................................... 217 mplab ice 4000 high-performance universal in-circuit emulator................................................... 217 mplab integrated development environment software.. 215 mplab pm3 device programmer .................................... 217 mplink object linker/mplib object librarian ................ 216 o opcode field descriptions............................................. 205 option_reg register................................................ 22, 82 osccon register.............................................................. 70 oscillator associated registers.................................................. 80 oscillator configurations................ ..................................... 69 oscillator delay examples.......................................... 72 special cases............................................................. 71 oscillator specifications.................................................... 231 oscillator start-up timer (ost) specifications ........................................................... 235 oscillator switching fail-safe clock monitor .............................................. 79 two-speed clock start-up ......................................... 78 osctune register............................................................ 76
PIC16F917/916/914/913 ds41250d-page 264 preliminary ? 2005 microchip technology inc. p p (stop) bit ........................................................................ 160 packaging ......................................................................... 249 marking ............................................................. 249, 250 pdip details.............................................................. 251 soic details ............................................................. 256 tssop details .......................................................... 256 paging, program memory ................................................... 29 pcl and pclath ............................................................... 29 computed goto ........................................................ 29 stack ........................................................................... 29 pcon register ................................................................. 190 pickit 1 flash starter kit................................................... 219 picstart plus development programmer ..................... 218 pie1 register ...................................................................... 24 pie2 register ...................................................................... 25 pin diagram pic16f913/916, 28-pin ................................................. 3 pic16f914/917, 40-pin ................................................. 2 pic16f914/917, 44-pin ................................................. 4 pinout description ............................................................... 10 pir1 register...................................................................... 26 pir2 register...................................................................... 27 porta associated registers .................................................. 40 pin descriptions and diagrams................................... 33 ra0 ............................................................................. 33 ra1 ............................................................................. 34 ra2 ............................................................................. 35 ra3 ............................................................................. 36 ra4 ............................................................................. 37 ra5 ............................................................................. 38 ra6 ............................................................................. 39 ra7 ............................................................................. 40 registers..................................................................... 31 specifications............................................................ 233 porta register ................................................................. 32 portb additional pin functions ............................................. 41 weak pull-up....................................................... 41 associated registers .................................................. 50 interrupt-on-change .................................................... 41 pin descriptions and diagrams................................... 44 rb0 ............................................................................. 44 rb1 ............................................................................. 44 rb2 ............................................................................. 44 rb3 ............................................................................. 44 rb4 ............................................................................. 46 rb5 ............................................................................. 47 rb6 ............................................................................. 48 rb7 ............................................................................. 49 registers..................................................................... 41 portb register ................................................................. 42 portc associated registers .................................................. 59 pin descriptions and diagrams................................... 52 rc0 ............................................................................. 52 rc1 ............................................................................. 52 rc2 ............................................................................. 52 rc3 ............................................................................. 54 rc4 ............................................................................. 55 rc5 ............................................................................. 56 rc6 ............................................................................. 57 rc6/tx/ck/sck/scl/seg9 pin .............................. 128 rc7 ............................................................................. 58 rc7/rx/dt pin......................................................... 129 rc7/rx/dt/sdi/sda/seg8 pin............................... 128 registers .................................................................... 51 specifications ........................................................... 233 trisc register......................................................... 127 portc register................................................................. 51 portd associated registers .................................................. 64 pin descriptions and diagrams .................................. 61 rd0 ............................................................................ 61 rd1 ............................................................................ 61 rd2 ............................................................................ 61 rd3 ............................................................................ 61 rd4 ............................................................................ 61 rd5 ............................................................................ 61 rd6 ............................................................................ 61 rd7 ............................................................................ 61 registers .................................................................... 60 portd register................................................................. 60 porte associated registers .................................................. 67 pin descriptions and diagrams .................................. 66 re0............................................................................. 66 re1............................................................................. 66 re2............................................................................. 66 re3............................................................................. 66 registers .................................................................... 65 porte register ................................................................. 65 power-down mode (sleep)............................................... 201 power-on reset ................................................................ 188 power-up timer (pwrt) .................................................. 188 specifications ........................................................... 235 precision internal oscillator parameters .......................... 232 prescaler shared wdt/timer0................................................... 83 switching prescaler assignment ................................ 83 pro mate ii universal device programmer ................... 217 product identification system ........................................... 271 program memory ................................................................ 13 map and stack (pic16f913/914) ............................... 13 map and stack (pic16f916/917) ............................... 13 paging ........................................................................ 29 programmable low-voltage detect (plvd) module ........ 125 programming, device instructions.................................... 205 pulse width modulation. see capture/compare/pwm, pwm mode. r r/w bit .............................................................................. 160 rcsta register adden bit ................................................................ 128 cren bit .................................................................. 128 ferr bit................................................................... 128 oerr bit .................................................................. 128 rx9 bit ..................................................................... 128 rx9d bit ................................................................... 128 spen bit........................................................... 127, 128 sren bit .................................................................. 128 reader response............................................................. 270 read-modify-write operations ......................................... 205 receive overflow indicator bit (sspov) .......................... 161 registers adcon0 (a/d control 0).......................................... 146 adcon1 (a/d control 1).......................................... 147 ansel (analog select) ............................................ 146 ccp1con (ccp control 2)...................................... 178
? 2005 microchip technology inc. preliminary ds41250d-page 265 PIC16F917/916/914/913 ccp2con (ccp control 1)...................................... 178 cmcon0 (comparator control 0) .............................. 93 cmcon1 (comparator control 1) .............................. 97 config (configuration word).................................. 186 eeadrh (eeprom address).................................. 154 eeadrl (eeprom address) .................................. 154 eecon1 (eeprom control 1)................................. 155 eedath (eeprom data)........................................ 154 eedatl (eeprom data) ........................................ 154 intcon (interrupt control)......................................... 23 iocb (portb interrupt-on-change)........................... 42 lcdcon (lcd control)............................................ 103 lcddatax (lcd datax) .......................................... 105 lcdps (lcd prescaler select) ................................ 104 lcdsen (lcd segment) .......................................... 105 lvdcon (low-voltage detect control).................... 125 option_reg ...................................................... 22, 82 osccon (oscillator control) ..................................... 70 osctune .................................................................. 76 pcon (power control) ............................................. 190 pie1 (peripheral interrupt enable 1)........................... 24 pie2 (peripheral interrupt enable 2)........................... 25 pir1 (peripheral interrupt register 1) ........................ 26 pir2 (peripheral interrupt register 2) ........................ 27 porta........................................................................ 32 portb........................................................................ 42 portc ....................................................................... 51 portd ....................................................................... 60 porte........................................................................ 65 rcsta (receive status and control)....................... 128 reset values............................................................. 192 reset values (special registers) ............................. 194 special function register map pic16f913/916................................................... 15 pic16f914/917................................................... 16 special register summary bank 0................................................................. 17 bank 1................................................................. 18 bank 2................................................................. 19 bank 3................................................................. 20 sspcon (sync serial port control) register........... 161 sspstat (sync serial port status) register........... 160 status.......................................................................... 21 t1con (timer1 control)............................................. 87 t2con (timer2 control)............................................. 90 trisa (porta tri-state) ........................................... 32 trisb (portb tri-state) ........................................... 42 trisc (portc tri-state) ........................................... 51 trisd (portd tri-state) ........................................... 60 trise (porte tri-state) ........................................... 65 txsta (transmit status and control) ...................... 127 vrcon (voltage reference control) ....................... 100 wdtcon (watchdog timer control) ....................... 200 wpub (weak pull-up portb) ................................... 43 reset................................................................................. 187 revision history ................................................................ 259 s s (start) bit ........................................................................ 160 sci. see usart serial communication interface. see usart. slave select synchronization ........................................... 166 smp bit ............................................................................. 160 software simulator (mplab sim)..................................... 216 software simulator (mplab sim30)................................. 216 special function registers ................................................. 14 spi mode .................................................................. 159, 166 associated registers................................................ 168 bus mode compatibility............................................ 168 effects of a reset ..................................................... 168 enabling spi i/o ....................................................... 164 master mode............................................................. 165 master/slave connection ......................................... 164 serial clock (sck pin).............................................. 159 serial data in (sdi pin)............................................. 159 serial data out (sdo pin) ........................................ 159 slave select.............................................................. 159 slave select synchronization ................................... 166 sleep operation........................................................ 168 spi clock.................................................................. 165 typical connection ................................................... 164 ssp overview spi master/slave connection................................... 164 ssp i 2 c operation ........................................................... 169 slave mode............................................................... 169 ssp module clock synchronization and the ckp bit ................... 175 spi master mode...................................................... 165 spi slave mode........................................................ 166 sspbuf ................................................................... 165 sspsr ..................................................................... 165 sspen bit......................................................................... 161 sspm bits......................................................................... 161 sspov bit ........................................................................ 161 status register ................................................................... 21 synchronous master reception associated registers................................................ 140 synchronous master transmission associated registers................................................ 139 synchronous serial port enable bit (sspen) .................. 161 synchronous serial port mode select bits (sspm).......... 161 synchronous serial port. see ssp synchronous slave reception associated registers................................................ 142 synchronous slave transmission associated registers................................................ 142 t t1con register ................................................................. 87 time-out sequence .......................................................... 190 timer0 associated registers.................................................. 83 external clock ............................................................ 82 external clock requirements ................................... 236 interrupt ...................................................................... 81 operation.................................................................... 81 t0cki ......................................................................... 82 timer0 module.................................................................... 81 timer1 associated registers.................................................. 89 asynchronous counter mode ..................................... 88 reading and writing ........................................... 88 external clock requirements ................................... 236 interrupt ...................................................................... 86 modes of operations .................................................. 86 operation during sleep .............................................. 89 prescaler .................................................................... 86 resetting of timer1 registers .................................... 89 resetting timer1 using a ccp trigger output .......... 88 timer1 gate inverting gate ..................................................... 86
PIC16F917/916/914/913 ds41250d-page 266 preliminary ? 2005 microchip technology inc. selecting source........................................... 86, 97 synchronizing c2out w/ timer1 ....................... 97 tmr1h register ......................................................... 85 tmr1l register.......................................................... 85 timer1 module with gate control ....................................... 85 timer2 ................................................................................. 90 associated registers.................................................... 91 operation .................................................................... 90 postscaler ................................................................... 90 pr2 register............................................................... 90 prescaler..................................................................... 90 tmr2 output .............................................................. 91 tmr2 register............................................................ 90 tmr2 to pr2 match interrupt ............................... 90, 91 timing diagrams a/d conversion ......................................................... 245 asynchronous master transmission ......................... 132 asynchronous master transmission (back-to-back) 132 asynchronous reception .......................................... 135 asynchronous reception with address byte first .... 137 asynchronous reception with address detect ......... 137 brown-out reset (bor) ............................................ 234 brown-out reset situations ...................................... 189 capture/compare/pwm............................................ 237 clko and i/o ........................................................... 233 clock synchronization .............................................. 176 comparator output ..................................................... 94 external clock........................................................... 231 fail-safe clock monitor (fscm) ................................. 80 i 2 c bus data ............................................................. 243 i 2 c bus start/stop bits.............................................. 242 i 2 c reception (7-bit address) ................................... 171 i 2 c slave mode (transmission, 10-bit address) ....... 174 i 2 c slave mode with sen = 0 (reception, 10-bit address).................................................. 172 i 2 c transmission (7-bit address) .............................. 173 int pin interrupt........................................................ 197 lcd interrupt timing in quarter-duty cycle drive.... 121 lcd sleep entry/exit when slpen = 1 or cs = 00 . 123 reset, wdt, ost and power-up timer ................... 234 slave synchronization .............................................. 166 spi master mode (cke = 1, smp = 1) ..................... 240 spi mode (master mode) .......................................... 165 spi mode (slave mode with cke = 0) ...................... 167 spi mode (slave mode with cke = 1) ...................... 167 spi slave mode (cke = 0) ....................................... 241 spi slave mode (cke = 1) ....................................... 241 synchronous reception (master mode, sren) ....... 141 synchronous transmission....................................... 139 synchronous transmission (through txen) ........... 139 time-out sequence case 1............................................................... 191 case 2............................................................... 191 case 3............................................................... 191 timer0 and timer1 external clock ........................... 235 timer1 incrementing edge.......................................... 86 two speed start-up .................................................... 79 type-a in 1/2 mux, 1/2 bias drive ............................ 111 type-a in 1/2 mux, 1/3 bias drive ............................ 113 type-a in 1/3 mux, 1/2 bias drive ............................ 115 type-a in 1/3 mux, 1/3 bias drive ............................ 117 type-a in 1/4 mux, 1/3 bias drive ............................ 119 type-a/type-b in static drive................................... 110 type-b in 1/2 mux, 1/2 bias drive ............................ 112 type-b in 1/2 mux, 1/3 bias drive ............................ 114 type-b in 1/3 mux, 1/2 bias drive ............................ 116 type-b in 1/3 mux, 1/3 bias drive ............................ 118 type-b in 1/4 mux, 1/3 bias drive ............................ 120 usart synchronous receive (master/slave) ......... 237 usart synchronous transmission (master/slave). 236 wake-up from interrupt............................................. 202 timing parameter symbology .......................................... 230 timing requirements i 2 c bus data............................................................. 244 i2c bus start/stop bits............................................. 243 spi mode .................................................................. 242 tmr1h register ................................................................. 85 tmr1l register.................................................................. 85 trisa registers .................................................................... 31 trisa register................................................................... 32 trisb registers .................................................................... 41 trisb register................................................................... 42 trisc registers .................................................................... 51 trisc register................................................................... 51 trisd registers .................................................................... 60 trisd register................................................................... 60 trise registers .................................................................... 65 trise register................................................................... 65 two-speed clock start-up mode........................................ 78 txsta register brgh bit .................................................................. 127 csrc bit .................................................................. 127 sync bit .................................................................. 127 trmt bit................................................................... 127 tx9 bit ...................................................................... 127 tx9d bit ................................................................... 127 txen bit ................................................................... 127 u ua..................................................................................... 160 update address bit, ua .................................................... 160 usart.............................................................................. 127 address detect enable (adden bit)........................ 128 asynchronous mode ................................................. 131 asynchronous receive (9-bit mode)......................... 136 asynchronous receive with address detect. see asynchronous receive (9-bit mode). asynchronous receiver............................................ 134 asynchronous reception.......................................... 134 asynchronous transmitter........................................ 131 baud rate generator (brg) .................................... 129 baud rate formula .......................................... 129 baud rates, asynchronous mode (brgh = 0) 130 baud rates, asynchronous mode (brgh = 1) 130 high baud rate select (brgh bit) .................. 127 sampling........................................................... 129 clock source select (csrc bit)............................... 127 continuous receive enable (cren bit)................... 128 framing error (ferr bit) ......................................... 128 mode select (sync bit) ........................................... 127 overrun error (oerr bit)......................................... 128 receive data, 9th bit (rx9d bit).............................. 128 receive enable, 9-bit (rx9 bit) ................................ 128 serial port enable (spen bit) .......................... 127, 128 single receive enable (sren bit) ........................... 128 synchronous master mode....................................... 138
? 2005 microchip technology inc. preliminary ds41250d-page 267 PIC16F917/916/914/913 requirements, synchronous receive .............. 237 requirements, synchronous transmission ...... 237 timing diagram, synchronous receive ........... 237 timing diagram, synchronous transmission ... 236 synchronous master reception................................ 140 synchronous master transmission........................... 138 synchronous slave mode ......................................... 141 synchronous slave reception.................................. 142 synchronous slave transmit .................................... 141 transmit data, 9th bit (tx9d)................................... 127 transmit enable (txen bit)...................................... 127 transmit enable, nine-bit (tx9 bit) .......................... 127 transmit shift register status (trmt bit)................ 127 v voltage reference. see comparator voltage reference (cv ref ) vrcon register............................................................... 100 w wake-up using interrupts ................................................. 201 watchdog timer (wdt) .................................................... 199 associated registers ................................................ 200 clock source............................................................. 199 modes ....................................................................... 199 period........................................................................ 199 specifications............................................................ 235 wcol bit .......................................................................... 161 wdtcon register ........................................................... 200 wpub register................................................................... 43 write collision detect bit (wcol)..................................... 161 www address.................................................................. 269 www, on-line support ....................................................... 5
PIC16F917/916/914/913 ds41250d-page 268 preliminary ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. preliminary ds41250d-page 269 PIC16F917/916/914/913 the microchip web site microchip provides online support via our www site at www.microchip.com. this web site is used as a means to make files and information easily available to customers. accessible by using your favorite internet browser, the web site contains the following information: ? product support ? data sheets and errata, application notes and sample programs, design resources, user?s guides and hardware support documents, latest software releases and archived software ? general technical support ? frequently asked questions (faq), technical support requests, online discussion groups, microchip consultant program member listing ? business of microchip ? product selector and ordering guides, latest microchip press releases, listing of seminars and events, listings of microchip sales offices, distributors and factory representatives customer change notification service microchip?s customer notification service helps keep customers current on microchip products. subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest. to register, access the microchip web site at www.microchip.com, click on customer change notification and follow the registration instructions. customer support users of microchip products can receive assistance through several channels: ? distributor or representative ? local sales office ? field application engineer (fae) ? technical support ? development systems information line customers should contact their distributor, representative or field application engineer (fae) for support. local sales offices are also available to help customers. a listing of sales offices and locations is included in the back of this document. technical support is available through the web site at: http://support.microchip.com in addition, there is a development systems information line which lists the latest versions of microchip?s development systems software products. this line also provides information on how customers can receive currently available upgrade kits. the development systems information line numbers are: 1-800-755-2345 ? united states and most of canada 1-480-792-7302 ? other international locations
PIC16F917/916/914/913 ds41250d-page 270 preliminary ? 2005 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip prod- uct. if you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this document. to : technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds41250d PIC16F917/916/914/913 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
? 2005 microchip technology inc. preliminary ds41250d-page 271 PIC16F917/916/914/913 product identification system to order or obtain information, e. g., on pricing or delivery, refer to the factory or the listed sales office . * jw devices are uv erasable and can be programmed to any device c onfiguration. jw devices meet the electrical requirement of each oscillator type. part no. x /xx xxx pattern package temperature range device device PIC16F917/916/914/913 (1) , PIC16F917/916/914/913t (2) temperature range i = -40 c to +85 c e= -40 c to +125 c package ml = micro lead frame (qfn, qfn-s) p = plastic dip pt = tqfp (thin quad flatpack) so = soic sp = skinny plastic dip ss = ssop pattern 3-digit pattern code for qtp (blank otherwise) examples: a) pic16f913-e/sp 301 = extended temp., skinny pdip package, 20 mhz, qtp pattern #301 b) pic16f913-i/so = industrial temp., soic package, 20 mhz note 1: f = standard voltage range lf = wide voltage range 2: t = in tape and reel.
ds41250d-page 272 preliminary ? 2005 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: http://support.microchip.com web address: www.microchip.com atlanta alpharetta, ga tel: 770-640-0034 fax: 770-640-0307 boston westborough, ma tel: 774-760-0087 fax: 774-760-0088 chicago itasca, il tel: 630-285-0071 fax: 630-285-0075 dallas addison, tx tel: 972-818-7423 fax: 972-818-2924 detroit farmington hills, mi tel: 248-538-2250 fax: 248-538-2260 kokomo kokomo, in tel: 765-864-8360 fax: 765-864-8387 los angeles mission viejo, ca tel: 949-462-9523 fax: 949-462-9608 san jose mountain view, ca tel: 650-215-1444 fax: 650-961-0286 toronto mississauga, ontario, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific australia - sydney tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing tel: 86-10-8528-2100 fax: 86-10-8528-2104 china - chengdu tel: 86-28-8676-6200 fax: 86-28-8676-6599 china - fuzhou tel: 86-591-8750-3506 fax: 86-591-8750-3521 china - hong kong sar tel: 852-2401-1200 fax: 852-2401-3431 china - shanghai tel: 86-21-5407-5533 fax: 86-21-5407-5066 china - shenyang tel: 86-24-2334-2829 fax: 86-24-2334-2393 china - shenzhen tel: 86-755-8203-2660 fax: 86-755-8203-1760 china - shunde tel: 86-757-2839-5507 fax: 86-757-2839-5571 china - qingdao tel: 86-532-502-7355 fax: 86-532-502-7205 asia/pacific india - bangalore tel: 91-80-2229-0061 fax: 91-80-2229-0062 india - new delhi tel: 91-11-5160-8631 fax: 91-11-5160-8632 japan - kanagawa tel: 81-45-471- 6166 fax: 81-45-471-6122 korea - seoul tel: 82-2-554-7200 fax: 82-2-558-5932 or 82-2-558-5934 malaysia - penang tel:011-604-646-8870 fax:011-604-646-5086 philippines - manila tel: 011-632-634-9065 fax: 011-632-634-9069 singapore tel: 65-6334-8870 fax: 65-6334-8850 taiwan - kaohsiung tel: 886-7-536-4818 fax: 886-7-536-4803 taiwan - taipei tel: 886-2-2500-6610 fax: 886-2-2508-0102 taiwan - hsinchu tel: 886-3-572-9526 fax: 886-3-572-6459 europe austria - weis tel: 43-7242-2244-399 fax: 43-7242-2244-393 denmark - ballerup tel: 45-4450-2828 fax: 45-4485-2829 france - massy tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany - ismaning tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy - milan tel: 39-0331-742611 fax: 39-0331-466781 netherlands - drunen tel: 31-416-690399 fax: 31-416-690340 england - berkshire tel: 44-118-921-5869 fax: 44-118-921-5820 w orldwide s ales and s ervice 04/20/05


▲Up To Search▲   

 
Price & Availability of PIC16F917

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X